結果
問題 | No.566 だいたい完全二分木 |
ユーザー |
![]() |
提出日時 | 2019-03-20 09:35:55 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 883 bytes |
コンパイル時間 | 492 ms |
コンパイル使用メモリ | 61,860 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-16 08:57:12 |
合計ジャッジ時間 | 1,100 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 11 |
ソースコード
#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; }