結果
| 問題 |
No.862 XORでX
|
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2019-08-09 23:18:43 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 2,000 ms |
| コード長 | 2,202 bytes |
| コンパイル時間 | 1,572 ms |
| コンパイル使用メモリ | 174,356 KB |
| 実行使用メモリ | 8,192 KB |
| 最終ジャッジ日時 | 2024-07-19 15:49:33 |
| 合計ジャッジ時間 | 4,372 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 28 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
int main() {
cin.tie(nullptr); ios::sync_with_stdio(false);
int n, x; cin >> n >> x;
if (n == 2) {
if (x == 1) {
cout << 2 << '\n';
cout << 3 << '\n';
} else {
cout << 1 << '\n';
cout << (x ^ 1) << '\n';
}
return 0;
}
set<int> res;
auto add = [&](int l, int r) -> void {
for (int i = l; i < r; ++i) {
res.insert(i);
}
};
if (n % 4 == 0) {
if (x < 4) {
if (n == 4) {
res.insert(16 | x);
res.insert(20);
res.insert(24);
res.insert(28);
} else {
add(1, n + 4);
res.erase(4 | x);
int y = x < 3 ? x + 1 : 1;
res.erase(y);
res.erase(4 | y);
}
} else {
add(1, 4);
int m = n / 4 - 1;
for (int i = 4; m; i += 4) {
if (i <= x and x < i + 4) continue;
add(i, i + 4);
--m;
}
res.insert(x);
}
} else if (n % 4 == 1) {
int m = n / 4;
for (int i = 4; m; i += 4) {
if (i <= x and x < i + 4) continue;
add(i, i + 4);
--m;
}
res.insert(x);
} else if (n % 4 == 2) {
if (x < 4) {
res.insert(4);
res.insert(4 | x);
int m = n / 4;
for (int i = 8; m; i += 4) {
if (i <= x and x < i + 4) continue;
add(i, i + 4);
--m;
}
} else {
for (int i = x / 4 * 4; i < x / 4 * 4 + 4; ++i) if (i != x) {
res.insert(i);
}
add(1, 4);
int m = n / 4 - 1;
for (int i = 8; m; i += 4) {
if (i <= x and x < i + 4) continue;
add(i, i + 4);
--m;
}
}
} else {
if (x < 4) {
res.insert(4 | x);
int y = x < 3 ? x + 1 : 1;
res.insert(y);
res.insert(4 | y);
} else {
for (int i = x / 4 * 4; i < x / 4 * 4 + 4; ++i) if (i != x) {
res.insert(i);
}
}
int m = n / 4;
for (int i = 8; m; i += 4) {
if (i <= x and x < i + 4) continue;
add(i, i + 4);
--m;
}
}
for (int e : res) {
cout << e << '\n';
}
}
risujiroh