結果
| 問題 | No.566 だいたい完全二分木 | 
| コンテスト | |
| ユーザー |  dnish | 
| 提出日時 | 2018-06-17 11:53:12 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 2,000 ms | 
| コード長 | 838 bytes | 
| コンパイル時間 | 1,592 ms | 
| コンパイル使用メモリ | 168,656 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-30 16:29:37 | 
| 合計ジャッジ時間 | 2,383 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 11 | 
ソースコード
#include "bits/stdc++.h"
#define REP(i,n,N) for(ll i=(n); i<(N); i++)
#define RREP(i,n,N) for(ll i=(N-1); i>=n; i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define p(s) cout<<(s)<<endl
#define p2(a,b) cout<<(a)<<" "<<(b)<<endl
typedef long long ll;
using namespace std;
const ll inf=1e18;
vector<int> ans;
void f(int L, int R) {
    if (L == 1 && R == 2) {
        ans.push_back(1);
        ans.push_back(2);
        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);
}
int main(){
    int K;
    cin>>K;
    int node=1;
    REP(i,0,K){
        node*=2;
    }
    f(1,node-2);
    cout<<node-1;
    REP(i,0,ans.size()){
        cout<<" "<<ans[i];
    }
    cout<<endl;
    return 0;
}
            
            
            
        