結果
| 問題 | No.566 だいたい完全二分木 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-09-08 22:54:16 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 522 bytes | 
| コンパイル時間 | 1,463 ms | 
| コンパイル使用メモリ | 165,704 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-07 05:49:38 | 
| 合計ジャッジ時間 | 2,146 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 11 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
int ans[1 << 12];
int K;
void solve(int cur, int& num) {
	if (cur * 2 + 1 < (1 << K) - 1) solve(cur * 2 + 1, num);
	if (num == 1) ans[cur] = 2;
	else if (num == 2) ans[cur] = 1;
	else ans[cur] = num;
	num++;
	if (cur * 2 + 2 < (1 << K) - 1) solve(cur * 2 + 2, num);
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> K;
	int num = 1;
	solve(0, num);
	cout << ans[0];
	for (int i = 1; i < (1 << K) - 1; i++) cout << " " << ans[i];
	cout << endl;
	return 0;
}
            
            
            
        