結果

問題 No.3 ビットすごろく
ユーザー YamyukiYamyuki
提出日時 2016-12-26 12:20:46
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 665 bytes
コンパイル時間 114 ms
コンパイル使用メモリ 25,680 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 00:15:43
合計ジャッジ時間 1,319 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 0 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 0 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:9:2: warning: implicit declaration of function ‘memset’ [-Wimplicit-function-declaration]
  memset(next,0,sizeof(next));
  ^~~~~~
main.c:9:2: warning: incompatible implicit declaration of built-in function ‘memset’
main.c:9:2: note: include ‘<string.h>’ or provide a declaration of ‘memset’
main.c:3:1:
+#include <string.h>
 int bitcount(int a){
main.c:9:2:
  memset(next,0,sizeof(next));
  ^~~~~~

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>
int bitcount(int a){
	if(a==0) return 0;
	return a%2+bitcount(a/2);
}
int main(){
	int s=0,n,i=0,next[10000],f[10000],t=1,p,tt;
	memset(next,0,sizeof(next));
	memset(f,0,sizeof(f));
	scanf("%d",&n);
	f[0]=1;
	while(i<t){
		tt=t;
		for(;i<t;i++){
			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]==0){
					next[tt]=next[i]+p;
					f[next[tt]]=1;
					tt++;
				}
			}
			if(next[i]-p>=0){
				if(f[next[i]-p]==0){
					next[tt]=next[i]-p;
					f[next[tt]]=1;
					tt++;
				}
			}
		}
		t=tt;
		s++;
	}
	if(f[n-1]==0) s=-1;
	printf("%d\n",s);
	return 0;
}
0