結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
moshiya02
|
| 提出日時 | 2018-03-16 14:10:13 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 651 bytes |
| コンパイル時間 | 563 ms |
| コンパイル使用メモリ | 64,544 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-01 08:57:33 |
| 合計ジャッジ時間 | 1,459 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
int main(){
int n;
cin >> n;
queue<int> q;
int dist[n+1];
int i;
for(i=1;i<n+1;i++)
dist[i] = -1;
q.push(1);
dist[1] = 1;
int count = 1;
while(q.size()){
int qf = q.front();
q.pop();
//speed calculation
int speed = 0;
for(i=qf;i>0;i=i>>1){
speed += i%2;
}
//push
int v[] = {1, -1};
int pos;
for(i=0;i<2;i++){
pos = qf + v[i] * speed;
if( 1<= pos && pos <= n && dist[pos] == -1 ){
q.push( pos );
dist[pos] = dist[qf] + 1;
}
}
}
cout << dist[n] << endl;
return 0;
}
moshiya02