結果

問題 No.862 XORでX
ユーザー QCFiumQCFium
提出日時 2019-08-09 23:18:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 167 ms / 2,000 ms
コード長 2,286 bytes
コンパイル時間 1,687 ms
コンパイル使用メモリ 175,004 KB
実行使用メモリ 8,304 KB
最終ジャッジ日時 2023-09-26 22:02:25
合計ジャッジ時間 6,600 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,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 17 ms
4,380 KB
testcase_09 AC 17 ms
4,380 KB
testcase_10 AC 17 ms
4,376 KB
testcase_11 AC 18 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 120 ms
6,904 KB
testcase_17 AC 116 ms
6,884 KB
testcase_18 AC 118 ms
6,976 KB
testcase_19 AC 121 ms
6,900 KB
testcase_20 AC 160 ms
8,100 KB
testcase_21 AC 163 ms
8,220 KB
testcase_22 AC 162 ms
8,160 KB
testcase_23 AC 164 ms
8,116 KB
testcase_24 AC 161 ms
8,108 KB
testcase_25 AC 161 ms
8,184 KB
testcase_26 AC 161 ms
8,176 KB
testcase_27 AC 163 ms
8,128 KB
testcase_28 AC 158 ms
8,096 KB
testcase_29 AC 167 ms
8,128 KB
testcase_30 AC 163 ms
8,104 KB
testcase_31 AC 166 ms
8,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int n = ri(), x = ri();
	if (n == 1) {
		std::cout << x << std::endl;
		return 0;
	}
	bool inv = false;
	if (x == 1 && n == 3) {
		std::cout << 2 << std::endl;
		std::cout << 4 << std::endl;
		std::cout << 7 << std::endl;
		return 0;
	} else if (x == 1 && n == 4) {
		std::cout << 1 << std::endl;
		std::cout << 2 << std::endl;
		std::cout << 4 << std::endl;
		std::cout << 6 << std::endl;
		return 0;
	} else if (x == 1 && n >= 99996) {
		int xxor = 0;
		std::set<int> res;
		for (int i = 1; i <= 100005; i++) res.insert(i), xxor ^= i;
		assert(xxor == 1);
		
		int cnt = 100005 - n;
		while (1) {
			std::set<int> remove;
			int cur = 0;
			for (int i = 0; i + 1 < cnt; i++) {
				int x = rand() % 100005 + 1;
				remove.insert(x);
				cur ^= x;
			}
			if ((int) remove.size() == cnt - 1 && !remove.count(cur)) {
				for (auto i : remove) res.erase(i);
				res.erase(cur);
				break;
			}
		}
		assert(res.size() == n);
		for (auto i : res) std::cout << i << std::endl;
		return 0;
	}
	if (x < 4) {
		// //// // / /
		int left = (n - 1) / 2 * 2;
		std::set<int> res;
		for (int i = 4; i < 4 + left; i++) res.insert(i), x ^= i;
		assert(x < 4);
		// std::cerr << "x:" << x << std::endl;
		
		// for (auto i : res) std::cout << i << std::endl;
		if (n - left == 1) {
			assert((int) res.size() == n - 1);
			res.insert(x);
		} else if (n - left == 2) {
			assert((int) res.size() == n - 2);
			if (x == 1) res.insert(2), res.insert(3);
			else res.insert(x ^ 1), res.insert(1);
		} else assert(0);
		
		for (auto i : res) std::cout << i << std::endl;
		return 0;
	}
	
	int left = n;
	if (left % 4) left -= left % 4, left += 4;
	
	std::set<int> res;
	for (int i = 1; i < left; i++) {
		if (i / 4 * 4 == x / 4 * 4) {
			left += 4;
			i += 3;
			continue;
		}
		res.insert(i);
	}
	int xorr = 0;
	for (auto i : res) xorr ^= i;
	int sz = res.size();
	for (int i = 0; i < (int) sz + 1 - n; i++) {
		assert(res.count(i + 1));
		res.erase(i + 1);
		xorr ^= i + 1;
	}
	// std::cerr << "xorr:" << xorr << std::endl;
	
	assert(xorr < 4);
	res.insert(x ^ xorr);
	// std::cerr << "size:" << res.size() << std::endl;
	
	assert(res.size() == n);
	for (auto i : res) std::cout << i << std::endl;
	
	return 0;
}
0