結果

問題 No.3 ビットすごろく
ユーザー Yamyuki
提出日時 2016-12-26 12:08:49
言語 C90
(gcc 12.3.0)
結果
RE  
実行時間 -
コード長 551 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 20,992 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-14 23:36:20
合計ジャッジ時間 4,529 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 9 RE * 24
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:8:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |         scanf("%d",&n);
      |         ^~~~~~~~~~~~~~

ソースコード

diff #

#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;
}
0