結果
| 問題 |
No.566 だいたい完全二分木
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2018-02-22 15:41:20 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,500 bytes |
| コンパイル時間 | 2,078 ms |
| コンパイル使用メモリ | 178,444 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-01 13:11:00 |
| 合計ジャッジ時間 | 2,416 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 WA * 1 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))
using ll = long long;
using P = std::tuple<int,int>;
const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
vector<int> v;
struct Tree{
shared_ptr<Tree> left;
int v;
shared_ptr<Tree> right;
Tree(shared_ptr<Tree> left, int v, shared_ptr<Tree> right)
: left(left), v(v), right(right) {}
};
void add(shared_ptr<Tree> &t, int v){
if(t){
if(v < t->v){
add(t->left, v);
}else{
add(t->right, v);
}
}else{
t = make_shared<Tree>(nullptr, v, nullptr);
}
}
int height(shared_ptr<Tree> t){
if(t){
return max(height(t->left), height(t->right)) + 1;
}
return 0;
}
int main(){
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int K;
std::cin >> K;
v.resize((1 << K) - 1);
iota(v.begin(), v.end(), 1);
random_device rnd;
mt19937 engine(rnd());
while(true){
shuffle(v.begin(), v.end(), engine);
shared_ptr<Tree> t = nullptr;
for(int x : v){
add(t, x);
}
int h = height(t);
if(K <= h && h <= 3 * K){
for(int i=0;i<v.size();++i){
std::cout << v[i] << " \n"[i+1 == v.size()];
}
break;
}
}
}
tottoripaper