結果
| 問題 | No.566 だいたい完全二分木 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2018-06-03 18:44:51 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 2,000 ms | 
| コード長 | 720 bytes | 
| コンパイル時間 | 607 ms | 
| コンパイル使用メモリ | 74,300 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-30 09:25:53 | 
| 合計ジャッジ時間 | 1,422 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 11 | 
ソースコード
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
vector<int> ans;
vector<int> nodes;
void constructTree(int l, int r){
    if(r-l < 2){
        ans.push_back(nodes[l]);
        if(r != l)  ans.push_back(nodes[r]);
        return;
    }
    int mid = (l+r)/2;
    ans.push_back(nodes[mid]);    
    constructTree(l, mid-1);
    constructTree(mid+1, r);
}
int main(){
    int k;
    cin >> k;
    
    int n = pow(2,k)-1;
    ans.push_back(n);
    for(int i = 1; i < n; i++){
        nodes.push_back(i);
    }
    // arguments are indices
    constructTree(0, n-2);
    for(int i = 0; i < n; i++){
        if(i)   cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}
            
            
            
        