結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2019-07-10 15:11:28 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 610 bytes |
コンパイル時間 | 1,195 ms |
コンパイル使用メモリ | 157,412 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-15 13:53:28 |
合計ジャッジ時間 | 2,111 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 1 WA * 32 |
ソースコード
#include "bits/stdc++.h" using namespace std; int bitCount(int bits) { int cnt = 0; for(int mask = 1; mask != 0; mask<<=1) { if( (bits & mask) != 0 ) ++cnt; } return cnt; } int main() { int N = 0; cin >> N; int count = 0; int pos = 1; int prev = 0; while(1) { if(pos ==N) break; int c = bitCount(pos); pos += c; if(pos > N) { pos -=2*c; if(prev == pos) cout << -1 << endl; return 0; } ++count; } cout << count << endl; return 0; }