結果
問題 | No.566 だいたい完全二分木 |
ユーザー | 🍮かんプリン |
提出日時 | 2019-03-20 09:35:55 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 883 bytes |
コンパイル時間 | 442 ms |
コンパイル使用メモリ | 62,272 KB |
実行使用メモリ | 4,352 KB |
最終ジャッジ日時 | 2023-10-14 14:19:50 |
合計ジャッジ時間 | 1,469 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,352 KB |
testcase_01 | AC | 1 ms
4,352 KB |
testcase_02 | AC | 2 ms
4,348 KB |
testcase_03 | AC | 1 ms
4,348 KB |
testcase_04 | AC | 2 ms
4,348 KB |
testcase_05 | AC | 1 ms
4,352 KB |
testcase_06 | AC | 2 ms
4,348 KB |
testcase_07 | AC | 2 ms
4,348 KB |
testcase_08 | AC | 1 ms
4,352 KB |
testcase_09 | AC | 2 ms
4,352 KB |
testcase_10 | AC | 2 ms
4,352 KB |
ソースコード
#include <iostream> #include <vector> #include <utility> #include <algorithm> #include <string> #include <stack> using ll = long long; #define MOD 1000000007 using namespace std; int K, p; int pow(int k,int n) { int s=1; for(int i=0;i<n;i++) { s*=k; } return s; } void printTree(int height, int rootsize) { if (height == 0) { if (rootsize == 1) { cout << rootsize + 1 << " "; cout << 1 << " "; } else if (p - 1 == rootsize){ return; } else { cout << rootsize + 1 << " "; } } else { cout << rootsize + 1 << " "; printTree(height - 1, rootsize - pow(2, height - 1)); printTree(height - 1, rootsize + pow(2, height - 1)); } } int main(){ cin >> K; p = pow(2, K); printTree(K-1, pow(2, K - 1)); return 0; }