結果

問題 No.3 ビットすごろく
ユーザー pigwinpigwin
提出日時 2017-06-12 23:37:34
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 933 bytes
コンパイル時間 1,559 ms
コンパイル使用メモリ 55,952 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-24 21:39:55
合計ジャッジ時間 2,070 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
4,348 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 1 ms
4,348 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 2 ms
4,348 KB
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;
#define MAX 10001
int BitCheck(int n){
	int count=0;
	int check=1;
	for(int i=0;;i++){
		if(n<(check<<i))break;
		if(n & (check<<i))count++;
	}
	return count;
}
int Smaller(int a,int b){
	return (a > b? b:a);
}
void Search(int dp[],int now,int n){
	if(now==n)return;	
	int move=BitCheck(now);
	int m=0,p=0;
	if((now+move)<(n+1)){
		if(dp[now+move]==-1){
			dp[now+move]=dp[now]+1;
			Search(dp,now+move,n);
		}else{
			dp[now+move]=Smaller(dp[now]+1,dp[now+move]);
			if(dp[now]+1 < dp[now+move])Search(dp,now+move,n);
		}
	}
	if((now-move)>0){
		if(dp[now-move]==-1){
			dp[now-move]=dp[now]+1;
			Search(dp,now-move,n);
		}else{
			dp[now-move]=Smaller(dp[now]+1,dp[now-move]);
			if(dp[now]+1 < dp[now-move])Search(dp,now-move,n);
		}
	}
}
int main(){
	int n=0;
	cin>>n;
	int dp[MAX];
	for(int i=0;i<=n;i++)dp[i]=-1;
	dp[1]=1;
	int now=1;
	Search(dp,now,n);
	cout<<dp[n]<<endl;
	return 0;
}
0