結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-26 12:05:49 |
| 言語 | C90(gcc15) (gcc 15.2.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 551 bytes |
| 記録 | |
| コンパイル時間 | 316 ms |
| コンパイル使用メモリ | 38,824 KB |
| 最終ジャッジ日時 | 2026-02-24 00:00:12 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 RE * 24 |
ソースコード
#include<stdio.h>
int bitcount(int a){
if(a==0) return 0;
return a%2+bitcount(a/2);
}
int s,n,i,next[10000],f[10000],t=1,p,tt;
int main(){
scanf("%d",&n);;
while(i<t){
tt=t;
for(;i<t;i++){
f[next[i]]=1;
if(next[i]==n-1){
t=0;
tt=0;
break;
}
p=bitcount(next[i]+1);
if(next[i]+p<n){
if(!f[next[i]+p]){
next[tt]=next[i]+p;
tt++;
}
}
if(next[i]-p>=0){
if(!f[next[i]-p]){
next[tt]=next[i]-p;
tt++;
}
}
}
t=tt;
s++;
}
if(f[n-1]==0) s=-1;
printf("%d\n",s);
return 0;
}