結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2020-02-12 16:16:33 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 967 bytes |
コンパイル時間 | 1,712 ms |
コンパイル使用メモリ | 169,668 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-04 01:53:41 |
合計ジャッジ時間 | 2,765 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | WA * 33 |
ソースコード
#include <bits/stdc++.h> using namespace std; int bitCount(int n){ int cn = 0; while(n != 0){ if(n % 2 == 1) cn++; n /= 2; } return cn; } int main(){ int N; cin >> N; vector<int> nums(N); for(int i = 0; i < N; i++){ nums.at(i) = (i + 1); } vector<int> ms(N); for(int i = 0; i < N; i++){ ms.at(i) = bitCount(nums.at(i)); } for(int i = 0; i < N; i++){ cout << ms.at(i); if(i == N-1){ cout << endl; }else{ cout << " "; } } int count = 0; int ans = 0; int index = 0; vector<int> flgs = vector<int>(N,0); while(count != N && index < N){ if(flgs.at(index) && index != 0){ ans = -1; break; } if(count + ms.at(index) <= N){ count += ms.at(index); }else if(count + ms.at(index) > N){ count -= ms.at(index); } flgs.at(index) = 1; index = count-1; ans++; cout << count << "->"; } cout << endl; cout << ans << endl; return 0; }