結果

問題 No.862 XORでX
ユーザー leaf_1415leaf_1415
提出日時 2019-08-09 23:15:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 2,899 bytes
コンパイル時間 635 ms
コンパイル使用メモリ 70,356 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 21:58:40
合計ジャッジ時間 5,072 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 16 ms
4,376 KB
testcase_09 AC 16 ms
4,376 KB
testcase_10 AC 16 ms
4,376 KB
testcase_11 AC 16 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 100 ms
4,380 KB
testcase_17 AC 98 ms
4,376 KB
testcase_18 AC 96 ms
4,376 KB
testcase_19 AC 97 ms
4,376 KB
testcase_20 AC 129 ms
4,384 KB
testcase_21 AC 126 ms
4,376 KB
testcase_22 AC 135 ms
4,380 KB
testcase_23 AC 129 ms
4,380 KB
testcase_24 AC 136 ms
4,376 KB
testcase_25 AC 130 ms
4,380 KB
testcase_26 AC 136 ms
4,376 KB
testcase_27 AC 135 ms
4,376 KB
testcase_28 AC 134 ms
4,376 KB
testcase_29 AC 137 ms
4,376 KB
testcase_30 AC 138 ms
4,376 KB
testcase_31 AC 137 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#define llint long long

using namespace std;

llint n, x;
vector<llint> ans;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> x;
	
	if(n == 1){
		cout << x << endl;
		return 0;
	}
	if(n == 2){
		if(x == 1){
			cout << 2 << endl;
			cout << 3 << endl;
		}
		else if(x == 2){
			cout << 1 << endl;
			cout << 3 << endl;
		}else{
			llint y = x ^ 1;
			cout << 1 << endl;
			cout << y << endl;
		}
		return 0;
	}
	
	llint rem = n;
	if(n % 4 == 0){
		if(x > 3){
			rem--;
			for(int i = 0; ; i++){
				if(x/4 == i) continue;
				for(int j = 0; j < 4; j++){
					if(i*4+j != 0 && rem) ans.push_back(i*4+j), rem--;
				}
				if(rem <= 0) break;
			}
			ans.push_back(x);
		}
		else{
			rem -= 4;
			for(int i = 1; ; i++){
				for(int j = 0; j < 4; j++){
					if(i*4+j != 0 && rem) ans.push_back(i*4+j), rem--;
				}
				if(rem <= 0) break;
			}
			int t = 3;
			if(ans.size()) t = ans.back();
			if(x != 1){
				ans.push_back(t+1);
				ans.push_back(t+2);
				if(x == 0) ans.push_back(2), ans.push_back(3);
				if(x == 2) ans.push_back(1), ans.push_back(2);
				if(x == 3) ans.push_back(1), ans.push_back(3);
			}
			else{
				ans.push_back(t+1);
				ans.push_back(t+3);
				ans.push_back(1), ans.push_back(2);
			}
		}
	}
	if(n % 4 == 1){
		rem--;
		for(int i = 1; ; i++){
			if(x/4 == i) continue;
			for(int j = 0; j < 4; j++){
				if(i*4+j != 0 && rem) ans.push_back(i*4+j), rem--;
			}
			if(rem <= 0) break;
		}
		ans.push_back(x);
	}
	if(n % 4 == 2){
		rem++;
		int i = x/4;
		for(int j = 0; j < 4; j++){
			if(i*4+j != 0 && rem) ans.push_back(i*4+j), rem--;
		}
		for(int i = 0; ; i++){
			if(x/4 == i) continue;
			for(int j = 0; j < 4; j++){
				if(i*4+j != 0 && rem) ans.push_back(i*4+j), rem--;
			}
			if(rem <= 0) break;
		}
		for(int j = 0; j < ans.size(); j++){
			if(ans[j] == x) ans.erase(ans.begin() + j);
		}
	}
	if(n % 4 == 3){
		if(x > 3){
			rem++;
			int i = x/4;
			for(int j = 0; j < 4; j++){
				if(i*4+j != 0 && rem) ans.push_back(i*4+j), rem--;
			}
			for(int i = 1; ; i++){
				if(x/4 == i) continue;
				for(int j = 0; j < 4; j++){
					if(i*4+j != 0 && rem) ans.push_back(i*4+j), rem--;
				}
				if(rem <= 0) break;
			}
			for(int j = 0; j < ans.size(); j++){
				if(ans[j] == x) ans.erase(ans.begin() + j);
			}
		}
		else{
			rem -= 3;
			for(int i = 1; ; i++){
				for(int j = 0; j < 4; j++){
					if(rem) ans.push_back(i*4+j), rem--;
				}
				if(rem <= 0) break;
			}
			int t = 3;
			if(ans.size()) t = ans.back();
			if(x != 1){
				ans.push_back(t+1);
				ans.push_back(t+2);
				if(x == 0) ans.push_back(1);
				if(x == 2) ans.push_back(3);
				if(x == 3) ans.push_back(2);
			}
			else{
				ans.push_back(t+1);
				ans.push_back(t+3);
				ans.push_back(3);
			}
		}
	}
	
	sort(ans.begin(), ans.end());
	for(int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
	
	return 0;
}
0