結果

問題 No.3 ビットすごろく
ユーザー mm
提出日時 2020-08-01 07:00:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 629 bytes
コンパイル時間 1,037 ms
コンパイル使用メモリ 63,812 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-21 18:17:35
合計ジャッジ時間 2,105 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1 ms
4,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 1 ms
4,384 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 2 ms
4,376 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>

using namespace std;

int cnt1(int a) {
  int cnt1 = 0;
  while (a != 0) {
    if (a & 0x00001 == 1) {
      cnt1++;
    }
    a = a >> 1;
  }
  return cnt1;
}

int main() {
  int n; 
  cin >> n;
  int cnt = 1;
  int w = 1;
  int a = 1;
  int ng;

  while (a != n && cnt < 1000) {
    w = cnt1(a);
    if (a + w > n) {
      if ((a - w) >= 0) {
        a -= w;
      } else {
        cout << -1 << endl;
        return -1;
      }
    } else {
      a += w;
    }
    cnt++;
  }
  // aaaaa 
  if (cnt == 1000) {
    cout << -1 << endl;
  } else {
    cout << cnt << endl;
  }
  return 0;
}
0