結果

問題 No.566 だいたい完全二分木
ユーザー firiexpfiriexp
提出日時 2019-03-28 19:10:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,614 bytes
コンパイル時間 766 ms
コンパイル使用メモリ 95,092 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-09 21:10:57
合計ジャッジ時間 1,645 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <limits>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

#include <chrono>
class xor_shift {
    uint32_t x, y, z, w;
public:
    xor_shift() : x(static_cast<uint32_t>((chrono::system_clock::now().time_since_epoch().count())&((1LL << 32)-1))),
    y(1068246329), z(321908594), w(1234567890) {};

    uint32_t urand(){
        uint32_t t;
        t = x ^ (x << 11);
        x = y; y = z; z = w;
        w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
        return w;
    };

    int rand(int n){
        if(n < 0) return -rand(-n);
        uint32_t t = numeric_limits<uint32_t>::max()/(n+1)*(n+1);
        uint32_t e = urand();
        while(e >= t) e = urand();
        return static_cast<int>(e%(n+1));
    }

    int rand(int a, int b){
        if(a > b) swap(a, b);
        return a+rand(b-a);
    }
};


int main() {
    int k;
    cin >> k;
    vector<int> v((1<<k)-1);
    for (int i = 0; i < (1<<k)-1; ++i) {
        v[i] = i+1;
    }
    if(k == 2){
        puts("1 2 3");
        return 0;
    }else if(k == 3){
        puts("5 3 2 4 1 6 7");
        return 0;
    }
    xor_shift rd;
    for (int i = 0; i < (1<<k)-1; ++i) {
        int y = rd.rand((1<<k)-i-2);
        swap(v[y], v[(1<<k)-i-2]);
    }
    for (int i = 0; i < (1<<k)-1; ++i) {
        if(i) cout << " ";
        cout << v[i];
    }
    return 0;
}
0