結果

問題 No.3 ビットすごろく
ユーザー tkzw_21tkzw_21
提出日時 2015-03-02 14:21:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 618 ms / 5,000 ms
コード長 612 bytes
コンパイル時間 1,178 ms
コンパイル使用メモリ 145,200 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 23:06:02
合計ジャッジ時間 9,962 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 34 ms
4,380 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 171 ms
4,376 KB
testcase_06 AC 44 ms
4,376 KB
testcase_07 AC 15 ms
4,376 KB
testcase_08 AC 108 ms
4,376 KB
testcase_09 AC 298 ms
4,376 KB
testcase_10 AC 405 ms
4,380 KB
testcase_11 AC 248 ms
4,376 KB
testcase_12 AC 159 ms
4,376 KB
testcase_13 AC 25 ms
4,376 KB
testcase_14 AC 391 ms
4,376 KB
testcase_15 AC 576 ms
4,376 KB
testcase_16 AC 554 ms
4,380 KB
testcase_17 AC 555 ms
4,376 KB
testcase_18 AC 19 ms
4,376 KB
testcase_19 AC 604 ms
4,376 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 401 ms
4,376 KB
testcase_23 AC 592 ms
4,376 KB
testcase_24 AC 618 ms
4,376 KB
testcase_25 AC 576 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 30 ms
4,376 KB
testcase_28 AC 479 ms
4,380 KB
testcase_29 AC 244 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 208 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef pair<int,int> P;
typedef pair<int,pair<int,int>> PP;
typedef long long ll;

const double EPS = 1e-8;
const int INF = 1e9;
const int MOD = 1e9+7;

int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};

int main(void) {
	int N;cin >> N;
	vector<int> dp(N+1,INF);
	dp[1] = 0;

	for(int l=0;l<N;l++)
	for(int i=1;i<N+1;i++){
		int mv = __builtin_popcount(i);
		if(dp[i] != INF){
			if(i+mv <= N)dp[i+mv] = min(dp[i+mv],dp[i]+1);
			if(i-mv >= 1)dp[i-mv] = min(dp[i-mv],dp[i]+1);
		}
	}
	if(dp[N]+1 >= INF)cout << -1 << endl;
	else cout << dp[N]+1 << endl;
	return 0;
}
0