結果

問題 No.566 だいたい完全二分木
ユーザー kk
提出日時 2020-08-14 16:25:15
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 642 bytes
コンパイル時間 2,101 ms
コンパイル使用メモリ 198,080 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-18 18:42:14
合計ジャッジ時間 2,953 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

void add(vector<int> &p, int l, int r) {
  if (l >= r) return;

  int m = (l + r) / 2;
  p.push_back(m);
  
  if (r - l > 1) {
    add(p, l, m);
    add(p, m+1, r);
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int k; cin >> k;
  int n = (1<<k);
 
  vector<int> p;
  REP (i, k+1) p.push_back(k + 1 - i);
  add(p, k+2, n);
  
  REP (i, p.size()) cout << p[i] << " ";
  cout << endl;
  
  return 0;
}
0