結果

問題 No.3 ビットすごろく
ユーザー tkzw_21tkzw_21
提出日時 2015-03-02 14:20:22
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 612 bytes
コンパイル時間 1,251 ms
コンパイル使用メモリ 145,352 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 06:31:22
合計ジャッジ時間 10,377 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 4 ms
4,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 16 ms
4,376 KB
testcase_08 AC 113 ms
4,376 KB
testcase_09 AC 299 ms
4,380 KB
testcase_10 AC 424 ms
4,376 KB
testcase_11 AC 244 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 526 ms
4,376 KB
testcase_17 AC 602 ms
4,380 KB
testcase_18 AC 19 ms
4,376 KB
testcase_19 AC 638 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 629 ms
4,376 KB
testcase_25 AC 613 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 30 ms
4,380 KB
testcase_28 AC 509 ms
4,376 KB
testcase_29 AC 256 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 218 ms
4,380 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