結果

問題 No.566 だいたい完全二分木
ユーザー ant2357
提出日時 2017-09-21 23:46:09
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 589 bytes
コンパイル時間 2,161 ms
コンパイル使用メモリ 196,008 KB
最終ジャッジ日時 2025-01-05 03:00:01
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

std::vector<int> binarySearch(std::vector<int> a, int left, int right) {
	std::vector<int> res = a;

	if (left > right) {
		return res;
	} else if (left == right) {
		res.push_back(left);
		return res;
	}

	int mid = (left + right) / 2;
	res.push_back(mid);

	return binarySearch(binarySearch(res, left, mid - 1), mid + 1, right);
}

int main() {
	int k;
	std::cin >> k;

	std::vector<int> res = binarySearch({1}, 2, (1 << k) - 1);
	for (int i = 0; i < res.size(); i++) {
		if (i) std::cout << " ";
		std::cout << res[i];
	}
	std::cout << std::endl;
	return 0;
}
0