結果
| 問題 |
No.566 だいたい完全二分木
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-03-28 19:10:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,614 bytes |
| コンパイル時間 | 855 ms |
| コンパイル使用メモリ | 95,964 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-15 19:06:04 |
| 合計ジャッジ時間 | 1,500 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 |
ソースコード
#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;
}