結果
問題 | No.3 ビットすごろく |
ユーザー |
![]() |
提出日時 | 2019-10-21 21:23:37 |
言語 | C++11 (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 619 bytes |
コンパイル時間 | 724 ms |
コンパイル使用メモリ | 64,324 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-02 17:51:29 |
合計ジャッジ時間 | 1,523 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 WA * 1 |
ソースコード
#include <iostream> #include <queue> using namespace std; int n; int x[10000],ans[10000]; int main(){ cin>>n; for(int i=1;i<=n;i++){ for(int j=0;j<14;j++){ x[i]+=(i>>j)%2; } } ans[1]=1; queue<int> q; q.push(1); while(q.size()){ int now=q.front(); q.pop(); int a=now-x[now],b=now+x[now]; if(1<=a&&ans[a]==0){ ans[a]=ans[now]+1; q.push(a); }if(b<=n&&ans[b]==0){ ans[b]=ans[now]+1; q.push(b); } } if(ans[n]==0)cout<<-1<<endl; else cout<<ans[n]<<endl; return 0; }