結果

問題 No.566 だいたい完全二分木
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-09-09 13:26:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,678 bytes
コンパイル時間 1,933 ms
コンパイル使用メモリ 167,040 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 23:56:48
合計ジャッジ時間 2,619 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/



vector<int> ans;
//---------------------------------------------------------------------------------------------------
void f(int L, int R) {
    if (L == 1 && R == 3) {
        ans.push_back(1);
        ans.push_back(2);
        ans.push_back(3);
        return;
    }

    if (L == R) {
        ans.push_back(L);
        return;
    }

    int md = (L + R) / 2;
    ans.push_back(md);
    f(L, md - 1);
    f(md + 1, R);
}
//---------------------------------------------------------------------------------------------------
void _main() {
    int K; cin >> K;
    int ma = 1;
    rep(i, 0, K) ma *= 2;
    f(1, ma - 1);

    int N = ans.size();
    rep(i, 0, N) {
        if (i) printf(" ");
        printf("%d", ans[i]);
    }
    printf("\n");
}
0