結果
問題 |
No.566 だいたい完全二分木
|
ユーザー |
![]() |
提出日時 | 2017-09-28 09:24:07 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 844 bytes |
コンパイル時間 | 692 ms |
コンパイル使用メモリ | 83,608 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-15 18:13:03 |
合計ジャッジ時間 | 1,300 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 11 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <cstring> #include <math.h> #include <cmath> #include <limits.h> #include <map> #include <set> #include <queue> #include <algorithm> #include <functional> #include <stdio.h> using namespace std; long long MOD = 1000000007; vector<int> A; vector<int> done; string ans = ""; void dfs( int l, int c, int r ) { if ( done[c] ) { return; } done[c] = 1; ans += to_string( A[c] ) + " "; dfs( l,(l+c)/2, c ); dfs( c,(r+c)/2, r ); } int main() { int K; cin >> K; int N = pow(2,K)-1; A.resize(N); done.resize(N+1); for ( int i = 0; i < N; i++ ) { A[i] = i+1; done[i+1] = 0; } dfs( 0, N/2+1, N ); cout << ans.erase( ans.length()-1, 1 ) << endl; return 0; }