結果

問題 No.566 だいたい完全二分木
ユーザー finefine
提出日時 2017-09-08 22:54:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 522 bytes
コンパイル時間 1,649 ms
コンパイル使用メモリ 162,300 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 20:49:35
合計ジャッジ時間 2,281 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0