結果

問題 No.566 だいたい完全二分木
コンテスト
ユーザー firiexp
提出日時 2019-03-28 19:10:16
言語 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
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,614 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 728 ms
コンパイル使用メモリ 93,484 KB
最終ジャッジ日時 2026-05-10 17:40:23
合計ジャッジ時間 2,555 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:14:13: error: 'uint32_t' does not name a type
   14 | using u32 = uint32_t;
      |             ^~~~~~~~
main.cpp:11:1: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
   10 | #include <bitset>
  +++ |+#include <cstdint>
   11 | 

ソースコード

diff #
raw source code

#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