結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-23 02:07:19 |
| 言語 | C90(gcc15) (gcc 15.2.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 746 bytes |
| 記録 | |
| コンパイル時間 | 150 ms |
| コンパイル使用メモリ | 26,040 KB |
| 最終ジャッジ日時 | 2026-02-23 23:58:01 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.c: In function 'bfs':
main.c:39:1: error: C++ style comments are not allowed in ISO C90
39 | // printf("%d\n",v);
| ^
main.c:39:1: note: (this will be reported only once per input file)
ソースコード
#include<stdio.h>
#define MAX 10000
#define INF 100000
int n,head=0,tail=0,queue[MAX];
int d[10001];
int used[10001];
int push(int x){
queue[tail]=x;
tail++;
}
int pop(){
int x;
x=queue[head];
head++;
return x;
}
int bitcount(int x){
int i=0;
while(x){
i+=x%2;
x=x/2;
}
return i;
}
int bfs(int start){
int v=1,r;
push(start);
d[start]=1;
used[start]=1;
while(1){
if(head==tail)return -1;
v=pop();
// printf("%d\n",v);
if(v==n)
return d[v];
r=bitcount(v);
if(v+r<=n&&used[v+r]==0){
push(v+r);
d[v+r]=d[v]+1;
used[v+r]=1;
}
if(v-r>=0&&used[v-r]==0){
push(v-r);
d[v-r]=d[v]+1;
used[v-r]=1;
}
}
}
int main(){
int start=1;
scanf("%d",&n);
printf("%d",bfs(start));
return 0;
}