結果

問題 No.862 XORでX
コンテスト
ユーザー 梧桐
提出日時 2026-05-20 04:17:19
言語 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,058 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,969 ms
コンパイル使用メモリ 112,268 KB
実行使用メモリ 14,756 KB
最終ジャッジ日時 2026-05-20 04:17:45
合計ジャッジ時間 7,939 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15 WA * 1 TLE * 1 -- * 11
権限があれば一括ダウンロードができます

ソースコード

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 {
        mt19937 rnd(time(0));
        unordered_set<int> s;
        while (true) {
            s.clear();
            int r = 0;
            while (s.size() < n - 2) {
                int v = rnd() % 100000 + 1;
                if (v != x && !s.count(v)) {
                    r ^= v;
                    s.insert(v);
                }
            }
            if (r != x && r <= 100005 && !s.count(r)) {
                s.insert(r);
                s.insert(x);
                break;
            }
        }
        for (auto e : s) {
            printf("%d\n", e);
        }
    }

    return 0;
}
0