結果
問題 | No.3 ビットすごろく |
ユーザー |
|
提出日時 | 2018-02-17 18:09:07 |
言語 | C++11 (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 854 bytes |
コンパイル時間 | 1,676 ms |
コンパイル使用メモリ | 163,148 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-24 12:15:33 |
合計ジャッジ時間 | 2,729 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 WA * 15 |
ソースコード
#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; }else if(t - w[t] >= 0 && !e[t - w[t]]){ Qu.push(t - w[t]); e[t - w[t]] = true; } } }