結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
Irmystp
|
| 提出日時 | 2014-11-26 21:13:32 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 872 bytes |
| コンパイル時間 | 1,357 ms |
| コンパイル使用メモリ | 163,444 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-01 07:07:46 |
| 合計ジャッジ時間 | 2,350 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
11 | scanf("%d", &N);
| ~~~~~^~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int N;
int step[10001];
bool visited[10001];
int main(){
scanf("%d", &N);
for(int x = 1; x <= N; x++){
int c = 0;
for(int y = x; y > 0; y /= 2) c += y&1;
step[x] = c;
}
queue<P> que;
que.push(P(1, 1));
fill(visited, visited+N+1, false);
P p;
while(!que.empty()){
p = que.front(); que.pop();
int s = p.first, c = p.second;
if(visited[s]) continue;
if(s == N) break;
visited[s] = true;
if(s - step[s] >= 1){
que.push(P(s-step[s], c+1));
}
if(s + step[s] <= N){
que.push(P(s+step[s], c+1));
}
}
if(p.first == N){
printf("%d\n", p.second);
}else{
puts("-1");
}
return 0;
}
Irmystp