結果

問題 No.862 XORでX
コンテスト
ユーザー 梧桐
提出日時 2026-05-20 04:40:52
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,824 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,257 ms
コンパイル使用メモリ 113,760 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-20 04:41:06
合計ジャッジ時間 4,875 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <cstdio>
#include <random>
#include <unordered_set>

using namespace std;

int n, x;

int main() {
    scanf("%d%d", &n, &x);

    if (n == 1) printf("%d\n", x);
    else if (n == 2) {
        if (x == 1) printf("%d\n%d\n", 2, 3);
        else printf("%d\n%d\n", 1, x ^ 1);
    } else if (n == 3) {
        if (x == 3) printf("%d\n%d\n%d\n", 1, 4, 1 ^ 3 ^ 4);
        else printf("%d\n%d\n%d\n", 1, 2, x ^ 1 ^ 2);
    } else {
        bool inv = false;
        if (n > 50002) {
            n = 100005 - n;
            x = 1 ^ x;
            inv = true;
        }

        mt19937 rnd(time(0));
        unordered_set<int> s;

        if (n == 0) {
        } else if (n == 1) {
            s.insert(x);
        } else if (n == 2) {
            if (x == 1) { s.insert(2); s.insert(3); }
            else { s.insert(1); s.insert(x ^ 1); }
        } else if (n == 3) {
            if (x == 3) { s.insert(1); s.insert(4); s.insert(1 ^ 3 ^ 4); }
            else { s.insert(1); s.insert(2); s.insert(x ^ 1 ^ 2); }
        } else {
            while (true) {
                s.clear();
                int r = 0;
                while ((int)s.size() < n - 2) {
                    int v = rnd() % 100000 + 1;
                    if (v != x && !s.count(v)) {
                        r ^= v;
                        s.insert(v);
                    }
                }
                if (r != x && r >= 1 && r <= 100005 && !s.count(r)) {
                    s.insert(r);
                    s.insert(x);
                    break;
                }
            }
        }

        if (inv) {
            for (int i = 1; i <= 100005; ++i) {
                if (!s.count(i)) printf("%d\n", i);
            }
        } else {
            for (auto e : s) printf("%d\n", e);
        }
    }

    return 0;
}
0