結果

問題 No.3 ビットすごろく
ユーザー ark27ark27
提出日時 2019-07-25 10:44:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 196 ms / 5,000 ms
コード長 932 bytes
コンパイル時間 1,387 ms
コンパイル使用メモリ 165,256 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 01:24:18
合計ジャッジ時間 4,980 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 10 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 51 ms
4,376 KB
testcase_06 AC 12 ms
4,376 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 31 ms
4,376 KB
testcase_09 AC 86 ms
4,376 KB
testcase_10 AC 128 ms
4,376 KB
testcase_11 AC 74 ms
4,380 KB
testcase_12 AC 49 ms
4,376 KB
testcase_13 AC 7 ms
4,380 KB
testcase_14 AC 114 ms
4,380 KB
testcase_15 AC 191 ms
4,380 KB
testcase_16 AC 165 ms
4,376 KB
testcase_17 AC 180 ms
4,376 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 196 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 117 ms
4,380 KB
testcase_23 AC 196 ms
4,376 KB
testcase_24 AC 194 ms
4,380 KB
testcase_25 AC 184 ms
4,384 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 9 ms
4,376 KB
testcase_28 AC 153 ms
4,376 KB
testcase_29 AC 72 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 64 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){return a/GCD(a,b)*b;}



int n;
	int dp[10010];

int sht(int num){
	int s=num;
		int cnt=0;
		while(s>0){
			if(s&1)cnt++;
			s>>=1;
		}
		return cnt;
}

void d(int a){
	int b=sht(a);
	if(a-b>0){
		if(dp[a-b]>dp[a]+1){
			dp[a-b]=dp[a]+1;
			d(a-b);
		}
	}
	if(a+b<n+1){
		if(dp[a+b]>dp[a]+1){
			dp[a+b]=dp[a]+1;
			d(a+b);
		}
	}
}

int main(){
	
	FOR(i,10005){
		dp[i]=MOD;
	}
	cin >> n;
	dp[1]=1;
	d(1);
	if(dp[n]==MOD){
		cout << -1 << endl;
	}else{
		cout << dp[n] << endl;
	}
}
0