結果

問題 No.3 ビットすごろく
ユーザー YamyukiYamyuki
提出日時 2016-12-26 11:59:55
言語 C90
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 513 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 20,992 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-08 17:40:58
合計ジャッジ時間 4,547 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 0 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 RE -
testcase_04 AC 1 ms
5,376 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 0 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 1 ms
5,376 KB
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 bit(int a){
	if(a==1) return 1;
	return a%2+bit(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){
				tt=0;
				break;
			}
			p=bit(next[i]+1);
			if(next[i]+p<n){
				if(!f[next[i]+p]){
					next[tt]=next[i]+p;
					tt++;
				}
			}
			if(next[i]-p>=0 && !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