結果

問題 No.566 だいたい完全二分木
ユーザー iwashi31iwashi31
提出日時 2017-09-08 22:45:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,260 bytes
コンパイル時間 797 ms
コンパイル使用メモリ 86,516 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 20:43:04
合計ジャッジ時間 1,314 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 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 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

void dfs(vector<int> &ret, int minV, int maxV) {
	if (minV > maxV) return;
	int val = (minV + maxV) / 2;
	ret.push_back(val);
	dfs(ret, minV, val - 1);
	dfs(ret, val + 1, maxV);
}

signed main() {
	int K;
	cin >> K;

	int N = pow(2, K) + 0.0000001 - 1;

	vector<int> ret;
	int first = min(N, 3 * K);
	for (int i = first; i >= 1; i--) ret.push_back(i);

	dfs(ret, first + 1, N);

	rep(i, N) {
		cout << ret[i] << ' ';
	}
	cout << endl;

    return 0;
}
0