結果

問題 No.862 XORでX
ユーザー mamekinmamekin
提出日時 2019-08-10 19:29:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 2,311 bytes
コンパイル時間 2,039 ms
コンパイル使用メモリ 122,316 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 23:37:15
合計ジャッジ時間 8,028 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

class Xorshift
{
private:
    uint32_t x, y, z, w;
public:
    Xorshift(uint32_t seed=88675123, int32_t loop=50){
        x = 123456789;
        y = 362436069;
        z = 521288629;
        w = seed;
        while(--loop >= 0){
            (*this)();
        }
    }
    uint32_t operator()(){
        uint32_t t=(x^(x<<11));
        x=y; y=z; z=w;
        return w=(w^(w>>19))^(t^(t>>8));
    }
    uint32_t operator()(uint32_t size){
        return (*this)() % size;
    }
    uint64_t get64(){
        uint64_t a = (*this)();
        uint64_t b = (*this)();
        return (a << 32) | b;
    }
    uint64_t get64(uint64_t size){
        return get64() % size;
    }
    template <class T>
    void shuffle(vector<T>& v){
        uint32_t n = v.size();
        for(uint32_t i=0; i<n-1; ++i){
            uint32_t j = (*this)(n-i) + i;
            swap(v[i], v[j]);
        }
    }
};
Xorshift xorshift;

const int MAX = 100005;

void solve(int n, int x, vector<bool>& ans)
{
    if(n > MAX / 2){
        int y = x;
        for(int i=1; i<=MAX; ++i)
            y ^= i;
        solve(MAX - n, y, ans);
        for(int i=1; i<=MAX; ++i)
            ans[i] = !ans[i];
        return;
    }

    vector<int> v(MAX);
    for(int i=0; i<MAX; ++i)
        v[i] = i + 1;

    for(;;){
        xorshift.shuffle(v);
        int y = x;
        for(int i=0; i<n-1; ++i)
            y ^= v[i];
        if(find(v.begin() + n - 1, v.end(), y) != v.end()){
            v[n-1] = y;
            ans.assign(MAX+1, false);
            for(int i=0; i<n; ++i)
                ans[v[i]] = true;
            return;
        }
    }
}

int main()
{
    int n, x;
    cin >> n >> x;

    vector<bool> ans;
    solve(n, x, ans);
    for(int i=1; i<=MAX; ++i){
        if(ans[i])
            cout << i << endl;
    }

    return 0;
}
0