結果

問題 No.3 ビットすごろく
ユーザー ふっぴーふっぴー
提出日時 2017-03-30 17:21:42
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 271 ms / 5,000 ms
コード長 705 bytes
コンパイル時間 629 ms
コンパイル使用メモリ 27,376 KB
実行使用メモリ 392,616 KB
最終ジャッジ日時 2023-09-14 00:37:55
合計ジャッジ時間 4,454 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 16 ms
23,172 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 80 ms
110,928 KB
testcase_06 AC 21 ms
28,500 KB
testcase_07 AC 5 ms
10,528 KB
testcase_08 AC 27 ms
70,004 KB
testcase_09 AC 74 ms
187,252 KB
testcase_10 AC 114 ms
264,632 KB
testcase_11 AC 59 ms
156,020 KB
testcase_12 AC 74 ms
104,780 KB
testcase_13 AC 13 ms
17,140 KB
testcase_14 AC 173 ms
247,804 KB
testcase_15 AC 270 ms
382,924 KB
testcase_16 AC 120 ms
330,388 KB
testcase_17 AC 134 ms
371,804 KB
testcase_18 AC 6 ms
13,036 KB
testcase_19 AC 144 ms
392,612 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 0 ms
4,376 KB
testcase_22 AC 176 ms
253,828 KB
testcase_23 AC 271 ms
392,336 KB
testcase_24 AC 146 ms
392,616 KB
testcase_25 AC 141 ms
383,320 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 9 ms
19,932 KB
testcase_28 AC 116 ms
315,868 KB
testcase_29 AC 61 ms
161,560 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 0 ms
4,376 KB
testcase_32 AC 52 ms
137,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <stdlib.h>
#define INF 1000000000;

int main(void){
	int n;
	scanf("%d",&n);
	int b[n+1];
	int i,j;
	for(i=1;i<n+1;i++){
		int j=i;
		int cnt=0;
		while(j/2!=0){
			if(j%2==1){
				cnt++;
			}
			j=j/2;
		}
		if(j==1){
			cnt++;
		}
		b[i]=cnt;
	}
	int dp[n+2][n+1];
	for(i=0;i<n+2;i++){
		for(j=0;j<n+1;j++){
			dp[i][j]=0;
		}
	}
	dp[1][1]=1;
	i=1;
	while(i<=n && dp[i][n]==0){
		for(j=1;j<n+1;j++){
			if(dp[i][j]==1){
				if(j+b[j]<n+1){
					dp[i+1][j+b[j]]=1;
				}
				if(j-b[j]>0){
					dp[i+1][j-b[j]]=1;
				}
			}
		}
		i++;
	}
	if(dp[i][n]==0){
		printf("-1\n");
	}else{
		printf("%d\n",i);
	}
	return 0;
}
	
0