結果
| 問題 |
No.566 だいたい完全二分木
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-09-09 16:35:14 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,009 bytes |
| コンパイル時間 | 2,287 ms |
| コンパイル使用メモリ | 198,804 KB |
| 最終ジャッジ日時 | 2025-01-05 02:52:34 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 11 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:28:19: warning: ‘void std::random_shuffle(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<int*, vector<int> >]’ is deprecated: use 'std::shuffle' instead [-Wdeprecated-declarations]
28 | random_shuffle(ans.begin(), ans.end());
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61,
from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
from main.cpp:1:
/usr/include/c++/13/bits/stl_algo.h:4581:5: note: declared here
4581 | random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last)
| ^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
void insert(int v, int u, vector<vector<int>> &ch) {
if (v < u) {
if (ch[u][0] == -1) return ch[u][0] = v, void();
return insert(v, ch[u][0], ch);
} else {
if (ch[u][1] == -1) return ch[u][1] = v, void();
return insert(v, ch[u][1], ch);
}
}
int max_dpt(int u, const vector<vector<int>> &ch) {
if (u == -1) return -1;
return max(max_dpt(ch[u][0], ch), max_dpt(ch[u][1], ch)) + 1;
}
int main() {
ios::sync_with_stdio(false);
int K;
cin >> K;
vector<int> ans;
for (int i = 0; i + 1 < 1 << K; ++i) {
ans.emplace_back(i);
}
while (true) {
random_shuffle(ans.begin(), ans.end());
vector<vector<int>> ch(1 << K, vector<int>(2, -1));
for (int i = 1; i < int(ans.size()); ++i) {
insert(ans[i], ans[0], ch);
}
int d = max_dpt(ans[0], ch);
if (K <= d and d <= 3 * K) break;
}
for (int i = 0; i < int(ans.size()); ++i) {
cout << ans[i] << " \n"[i + 1 == int(ans.size())];
}
return 0;
}