結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2015-05-31 18:40:53 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 636 bytes |
コンパイル時間 | 989 ms |
コンパイル使用メモリ | 61,932 KB |
実行使用メモリ | 10,020 KB |
最終ジャッジ日時 | 2024-07-06 13:04:55 |
合計ジャッジ時間 | 7,159 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 8 WA * 3 TLE * 1 -- * 21 |
ソースコード
#include<iostream> #include<algorithm> #include<vector> using namespace std; int henkan(int num){ int c=0; while(num>0){ if(num%2==1){ c++; } num = num/2; } return c++; } int solv(int N){ int walk; vector<int> flag(N+1,0); int pos = 1, count = 1; while(true){ flag[pos] = 1; walk = henkan(pos); if(pos+walk == N){ return count+1; }else if(pos+walk < N){ if(flag[pos+walk]==0){ pos = pos+walk; count++; } }else{ if(flag[pos-walk] == 0){ pos = pos-walk; count++; }else{ return -1; } } } } int main(){ int N; cin>>N; cout<<solv(N)<<endl; return 0; }