Submission #69155363


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

/////////////////// メイン ///////////////////

int main () {
  
  //////////////////// 入力 ////////////////////

  int n, k;
  cin >> n >> k;

  //////////////// 出力変数定義 ////////////////

  // 1のアンバランスさが発生するかどうか
  bool flag = false;

  // 数列、バックトレースしたいので終状態で初期化する
  deque<int> result(1,k);

  //////////////////// 処理 ////////////////////

  // バックトレースして、終状態から初期状態を求める
  // この作業を1+2+4+……+2^(n-1)回やる、つまり2^n-1回ループ
  for (int i=0; i<(1<<n)-1; i++) {

    // とりあえず先頭を取り出す
    int num = result.front();
    result.pop_front();

    // 奇数だったら、1のアンバランスさが発生することは避けられない
    if (num%2) flag = true;

    // 半分(切り捨て)と半分(切り上げ)を戻す
    result.emplace_back(num/2);
    result.emplace_back((num+1)/2);

  }

  //////////////////// 出力 ////////////////////

  // 最小アンバランスさを出力
  if (flag) cout << 1 << endl;
  else cout << 0 << endl;

  // 本体を出力
  for (size_t i=0; i<result.size(); i++) {
    cout << result.at(i);
    if (i!=result.size()-1) {
      cout << " ";
    }
  }
  cout << endl;

  //////////////////// 終了 ////////////////////

  return 0;

}

Submission Info

Submission Time
Task D - Least Unbalanced
User wightou
Language C++ 23 (gcc 12.2)
Score 400
Code Size 1488 Byte
Status AC
Exec Time 70 ms
Memory 8976 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 25
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3528 KiB
00_sample_01.txt AC 1 ms 3540 KiB
01_random_00.txt AC 1 ms 3476 KiB
01_random_01.txt AC 1 ms 3532 KiB
01_random_02.txt AC 1 ms 3492 KiB
01_random_03.txt AC 1 ms 3484 KiB
01_random_04.txt AC 1 ms 3488 KiB
01_random_05.txt AC 1 ms 3536 KiB
01_random_06.txt AC 1 ms 3472 KiB
01_random_07.txt AC 1 ms 3492 KiB
01_random_08.txt AC 1 ms 3412 KiB
01_random_09.txt AC 1 ms 3544 KiB
01_random_10.txt AC 1 ms 3408 KiB
01_random_11.txt AC 1 ms 3552 KiB
01_random_12.txt AC 1 ms 3528 KiB
01_random_13.txt AC 2 ms 3556 KiB
01_random_14.txt AC 3 ms 3628 KiB
01_random_15.txt AC 5 ms 3812 KiB
01_random_16.txt AC 10 ms 4020 KiB
01_random_17.txt AC 18 ms 4572 KiB
01_random_18.txt AC 35 ms 5652 KiB
01_random_19.txt AC 70 ms 8976 KiB
01_random_20.txt AC 1 ms 3532 KiB
01_random_21.txt AC 5 ms 3728 KiB
01_random_22.txt AC 1 ms 3532 KiB