結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 15 ms
4,376 KB
testcase_08 AC 111 ms
4,376 KB
testcase_09 AC 300 ms
4,376 KB
testcase_10 AC 418 ms
4,380 KB
testcase_11 AC 250 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 533 ms
4,376 KB
testcase_17 AC 591 ms
4,380 KB
testcase_18 AC 19 ms
4,380 KB
testcase_19 AC 625 ms
4,376 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 623 ms
4,376 KB
testcase_25 AC 606 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 33 ms
4,380 KB
testcase_28 AC 509 ms
4,376 KB
testcase_29 AC 258 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 218 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);
		}
	}
	cout << dp[N]+1 << endl;
	return 0;
}
0