結果

問題 No.3 ビットすごろく
ユーザー Mr.SpockMr.Spock
提出日時 2020-12-03 15:54:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 604 bytes
コンパイル時間 1,820 ms
コンパイル使用メモリ 170,360 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-10-12 01:29:39
合計ジャッジ時間 6,508 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	queue<int>q;
	vector<int>dp(n + 1, 1e9);
	dp[1] = 1;
	q.push(1);
	while (!q.empty()) {
		int nxt = q.front();
		q.pop();
		int b = __builtin_popcount(nxt);
		if (nxt - b >= 1 && dp[nxt - b] > 1 + dp[nxt]) {
			dp[nxt - b] = 1 + dp[nxt];
			q.push(b - nxt);
		}
		if (nxt + b <= n && dp[nxt + b] > 1 + dp[nxt]) {
			dp[nxt + b] = 1 + dp[nxt];
			q.push(b + nxt);
		}
	}
	int ans = 0;
	if (dp[n] == 1e9)ans = -1;
	else ans = dp[n];
	cout << ans << endl;
}
0