結果

問題 No.566 だいたい完全二分木
コンテスト
ユーザー 🍮かんプリン
提出日時 2019-03-20 09:35:55
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 883 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 394 ms
コンパイル使用メモリ 82,796 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-05 13:59:32
合計ジャッジ時間 1,269 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <stack>
using ll = long long;
#define MOD 1000000007
using namespace std;

int K, p;

int pow(int k,int n) {
    int s=1;
    for(int i=0;i<n;i++) {
        s*=k;
    }
    return s;
}

void printTree(int height, int rootsize) {
    if (height == 0) {
        if (rootsize == 1) {
            cout << rootsize + 1 << " ";
            cout << 1 << " ";
        }
        else if (p - 1 == rootsize){
            return;
        }
        else {
             cout << rootsize + 1 << " ";
        }
    }
    else {
        cout << rootsize + 1 << " ";
        printTree(height - 1, rootsize - pow(2, height - 1));
        printTree(height - 1, rootsize + pow(2, height - 1));
    }
}

int main(){
    cin >> K;
    p = pow(2, K);
    printTree(K-1, pow(2, K - 1));
    return 0;
}
0