結果

問題 No.3 ビットすごろく
ユーザー snrnsidysnrnsidy
提出日時 2021-02-21 01:06:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 836 bytes
コンパイル時間 4,199 ms
コンパイル使用メモリ 181,380 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 03:37:34
合計ジャッジ時間 3,412 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

int dp[10001];

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;

	cin >> N;

	fill(dp,dp+10001,1e9);

	dp[1] = 1;
	priority_queue <pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pque;
	pque.push(make_pair(dp[1],1));
	
	while(!pque.empty())
	{
		int now = pque.top().second;
		pque.pop();

		int cnt = 0;
		int val = now;
		while(val > 0)
		{
			if(val%2==1)
			{
				cnt++;
			}
			val/=2;
		}
		if(now-cnt>0)
		{
			if(dp[now-cnt] > dp[now] + 1)
			{
				dp[now-cnt] = dp[now] + 1;
				pque.push(make_pair(dp[now-cnt],now-cnt));
			}
		}
		if(now+cnt<=N)
		{
			if(dp[now+cnt] > dp[now] + 1)
			{
				dp[now+cnt] = dp[now] + 1;
				pque.push(make_pair(dp[now+cnt],now+cnt));
			}
		}
	}

	cout << dp[N] << '\n';
	
	return 0;
}
0