結果

問題 No.862 XORでX
ユーザー merom686merom686
提出日時 2019-08-09 22:49:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 2,608 bytes
コンパイル時間 1,648 ms
コンパイル使用メモリ 75,912 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 21:09:01
合計ジャッジ時間 3,283 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 3 ms
4,384 KB
testcase_11 AC 3 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 6 ms
4,380 KB
testcase_20 AC 7 ms
4,380 KB
testcase_21 AC 7 ms
4,384 KB
testcase_22 AC 8 ms
4,380 KB
testcase_23 AC 8 ms
4,384 KB
testcase_24 AC 7 ms
4,380 KB
testcase_25 AC 8 ms
4,380 KB
testcase_26 AC 8 ms
4,380 KB
testcase_27 AC 8 ms
4,380 KB
testcase_28 AC 8 ms
4,384 KB
testcase_29 AC 8 ms
4,380 KB
testcase_30 AC 8 ms
4,380 KB
testcase_31 AC 8 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    constexpr int A = 100005;
    int n, x;
    cin >> n >> x;

    int b = n > A - n;
    if (b) {
        n = A - n;
        for (int i = 1; i <= A; i++) {
            x ^= i;
        }
    }

    vector<int> r(A + 1);
    int c = x < 4 ? 4 : 1;

    switch (n % 4) {
    case 0:
        if (x != 0) {
            r[x] = 1;
            r[1 * c] = 1;
            r[2 * c] = 1;
            r[3 * c] = 1;
            n -= 4;
        }
        break;
    case 1:
        if (x != 0) {
            r[x] = 1;
        } else {
            int s = 0;
            for (int j = 0; j < 4; j++) {
                int t = 3 << j;
                r[t] = 1;
                s ^= t;
            }
            r[s] = 1;
            n -= 4;
        }
        break;
    case 2:
        if (x != 0) {
            r[x ^ c] = 1;
            r[c] = 1;
        } else {
            int s = 0;
            for (int j = 0; j < 5; j++) {
                int t = 3 << j;
                r[t] = 1;
                s ^= t;
            }
            r[s] = 1;
            n -= 4;
        }
        break;
    case 3:
        r[x ^ 1 * c] = 1;
        r[x ^ 2 * c] = 1;
        r[x ^ 3 * c] = 1;
        break;
    }
    n -= n % 4;

    for (int i = 4; n > 0; i += 4) {
        int f = 0;
        for (int j = 0; j < 4; j++) {
            if (r[i + j]) f = 1;
        }
        if (f == 0) {
            for (int j = 0; j < 4; j++) {
                r[i + j] = 1;
            }
            n -= 4;
        }
    }

    n = x = 0;
    for (int i = 1; i <= A; i++) {
        if (r[i] ^ b) {
            cout << i << '\n';
            n++;
            x ^= i;
        }
    }
    cout << flush;

    //cout << n << ' ' << x << endl;

    //Nが立っているビット数以下なら簡単
    //より大きいとき、1つのビットだけが立ってるやつを除いて適当に取る 適当に取る過程でpopcntをコントロールできない
    //1<<16のビットを持つ数が少ない?個数だけで言えば多いよな
    //4の倍数から連続する4つのxorは0になる これで数を稼ぐ
    //n%4で場合分け 1のときは簡単 0のときは1,10,11で0を作る、ただし... 2のときはx^1と1、ただしx==1のときはx^10と10 3のときはx^1,x^10,x^11、ただしx<4のときはx^100,x^1000,x^1100
    //反転して0になった場合

    return 0;
}
0