結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2018-11-27 22:16:09 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 720 bytes |
コンパイル時間 | 607 ms |
コンパイル使用メモリ | 65,080 KB |
実行使用メモリ | 554,424 KB |
最終ジャッジ日時 | 2024-06-24 10:19:58 |
合計ジャッジ時間 | 7,241 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 MLE * 1 -- * 29 |
ソースコード
#include <iostream> #include <queue> using namespace std; int bpop(int n){ int m=n%2; for(;n/=2;)m+=n%2; return m; } int main(){ int a[10001]={0,1},n,i=1,flag=-1; queue<int> que; cin>>n; que.push(i); while (1){ if (i==n) { flag = 0; break; } if (i-bpop(i) > 1 && i-bpop(i) <= n) { a[i-bpop(i)] = a[i] + 1; que.push(i-bpop(i)); } if (i+bpop(i) > 1 && i+bpop(i) <= n) { a[i+bpop(i)] = a[i] + 1; que.push(i+bpop(i)); } que.pop(); if (que.empty()) break; i=que.front(); } if (flag) cout<<-1<<"\n"; else cout<<a[i]<<"\n"; return 0; }