結果

問題 No.3 ビットすごろく
ユーザー TLwiegehttTLwiegehtt
提出日時 2015-07-08 16:33:03
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 820 bytes
コンパイル時間 734 ms
コンパイル使用メモリ 24,872 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-13 23:16:20
合計ジャッジ時間 1,920 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 0 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 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,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 0 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,500 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,500 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 0 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 0 ms
4,380 KB
testcase_31 AC 0 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#define MOD (5000)


int main(void){
	int i,n;
	
	int st=0,goal=0;
	int next[5000];
	int s[10100];
	
	for(i=0;i<5000;i++){next[i]=0;}
	for(i=0;i<10100;i++){s[i]=-1;}
	
	scanf("%d", &n);
	
	s[1] = 1;
	next[goal] = 1;
	goal++;
	
	while(st!=goal){
		int bit=0,tmp;
		int nowPos = next[st];
		int nextPos;
		
		st = (st+1)%MOD;
		
		if( nowPos == n ){
			break;
		}
		
		tmp = nowPos;
		while(tmp>0){
			if(tmp%2 == 1){
				bit++;
			}
			tmp >>= 1;
		}
		
		nextPos = nowPos - bit;
		if( 1 <= nextPos && s[nextPos] == -1 ){
			next[goal] = nextPos;
			s[nextPos] = s[nowPos]+1;
			goal = (goal+1)%MOD;
		}
		
		nextPos = nowPos + bit;
		if( nextPos <= n && s[nextPos] == -1 ){
			next[goal] = nextPos;
			s[nextPos] = s[nowPos]+1;
			goal = (goal+1)%MOD;
		}
		
	}
	
	
	printf("%d\n", s[n]);
	return 0;
}
0