結果

問題 No.3 ビットすごろく
ユーザー m
提出日時 2020-08-01 07:09:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 627 bytes
コンパイル時間 523 ms
コンパイル使用メモリ 63,488 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-07 12:10:00
合計ジャッジ時間 1,449 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 15
権限があれば一括ダウンロードができます

ソースコード

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 < 2000) {
    w = cnt1(a);
    if (a + w > n) {
      if (a - w >= 1) {
        a -= w;
      } else {
        cout << -1 << endl;
        return -1;
      }
    } else {
      a += w;
    }
    cnt++;
  }
  // aaaaa 
  if (cnt == 2000) {
    cout << -1 << endl;
  } else {
    cout << cnt << endl;
  }
  return 0;
}
0