結果

問題 No.862 XORでX
ユーザー QCFiumQCFium
提出日時 2019-08-09 23:12:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,834 bytes
コンパイル時間 1,619 ms
コンパイル使用メモリ 173,392 KB
実行使用メモリ 8,268 KB
最終ジャッジ日時 2023-09-26 21:53:09
合計ジャッジ時間 7,050 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 RE -
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 18 ms
4,380 KB
testcase_09 AC 18 ms
4,376 KB
testcase_10 AC 18 ms
4,376 KB
testcase_11 AC 18 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 120 ms
6,944 KB
testcase_17 AC 121 ms
6,936 KB
testcase_18 AC 120 ms
6,968 KB
testcase_19 AC 121 ms
6,844 KB
testcase_20 AC 163 ms
8,164 KB
testcase_21 AC 166 ms
8,228 KB
testcase_22 AC 164 ms
8,268 KB
testcase_23 AC 162 ms
8,248 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 WA -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 AC 160 ms
8,220 KB
testcase_31 AC 169 ms
8,048 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;
	}
	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 == 99999) {
		for (int i = 2; i <= 100000; i++) std::cout << i << std::endl;
		return 0;
	}
	if (x < 4) {
		if (n < 4 || n > 99996) assert(0);
		// //// // / /
		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