結果
| 問題 |
No.3 ビットすごろく
|
| ユーザー |
|
| 提出日時 | 2018-02-17 15:54:03 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 853 bytes |
| コンパイル時間 | 1,380 ms |
| コンパイル使用メモリ | 162,808 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-24 12:11:48 |
| 合計ジャッジ時間 | 2,444 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 WA * 15 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
int N,w[10000],c = 0;
bool e[10000];
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;
}
}
}