結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2018-02-17 18:33:09 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 858 bytes |
コンパイル時間 | 1,836 ms |
コンパイル使用メモリ | 161,976 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-24 12:17:16 |
合計ジャッジ時間 | 3,286 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 WA * 21 |
ソースコード
#include<bits/stdc++.h> using namespace std; int N,w[10001],c = 0; bool e[10001]; queue<int> Qu; int main(){ cin >> N; for(int i = 1; i <= N; i++) e[i] = false; for(int i = 1; i <= N; i++){ int tw = 1; int t = i; while(t != 1){ if(t%2) tw++; t /= 2; } w[i] = tw; } Qu.push(1); while(true){ if(Qu.empty()){ cout << -1 << endl; return 0; } int t = Qu.front(); Qu.pop(); c++; if(t == N){ cout << c << endl; return 0; } if(t + w[t] <= N && !e[t + w[t]]){ Qu.push(t + w[t]); e[t + w[t]] = true; } if(t - w[t] >= 0 && !e[t - w[t]]){ Qu.push(t - w[t]); e[t - w[t]] = true; } } }