結果

問題 No.862 XORでX
ユーザー finefine
提出日時 2019-08-09 23:15:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,532 bytes
コンパイル時間 1,949 ms
コンパイル使用メモリ 181,412 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-26 21:59:15
合計ジャッジ時間 5,844 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

//引数unzipには圧縮前のvectorを入れる
int compress(vector<ll>& unzip, map<ll, int>& zip) {
    sort(unzip.begin(), unzip.end());
    unzip.erase(unique(unzip.begin(), unzip.end()), unzip.end());
    for (int i = 0; i < unzip.size(); i++) {
        zip[unzip[i]] = i;
    }
    return unzip.size();
}

bool judge(vector<ll>& ans) {
    int n = ans.size();
    for (ll x : ans) {
        if (x <= 0 || x > 100005) return false;
    }

    map<ll, int> dummy;
    return compress(ans, dummy) == n;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, x;
    cin >> n >> x;
    
    vector<ll> ans;
    map<ll, int> dummy;

    mt19937 mt(0);
    do {
        ans.assign(n, 0);
        for (int i = 0; i < 17; i++) {
            vector<int> b1(n, 0);
            if (x & (1 << i)) {
                int cnt = n / 2;
                cnt += 1 - cnt % 2;
                for (int j = 0; j < cnt; j++) b1[j] = 1;
            } else {
                int cnt = n / 2;
                cnt += cnt % 2;
                for (int j = 0; j < cnt; j++) b1[j] = 1;
            }
            shuffle(b1.begin(), b1.end(), mt);

            for (int j = 0; j < n; j++) {
                ans[j] |= (b1[j] << i);
            }
        }

        sort(ans.begin(), ans.end());
        if (x & (1 << 17)) {
            ans[0] |= (1 << 17);
        }
    } while (!judge(ans));

    for (ll x : ans) {
        cout << x << "\n";
    }
    return 0;
}
0