結果

問題 No.3 ビットすごろく
ユーザー hanage
提出日時 2023-11-05 02:10:37
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 697 bytes
コンパイル時間 1,613 ms
コンパイル使用メモリ 172,592 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-25 22:22:31
合計ジャッジ時間 2,720 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 WA * 17 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
	int N;
	cin >> N;
	const int inf = 11111;
	vector<int> dist(N + 1, inf);
	dist[1] = 1;
	queue<int> que;
	que.push(1);
	while (!que.empty()) {
		int cur = que.front();
		que.pop();
		int nx1 = cur + __builtin_popcount(cur);
		int nx2 = cur + __builtin_popcount(cur);
		if (1 <= nx1) {
			if (dist[nx1] > dist[cur] + 1) {
				dist[nx1] = dist[cur] + 1;
				que.push(nx1);
			}
		}
		if (nx2) {
			if (dist[nx2] > dist[cur] + 1) {
				dist[nx2] = dist[cur] + 1;
				que.push(nx2);
			}
		}
	}
	int ans = (dist[N] == inf ? -1 : dist[N]);
	// for (int i = 1; i <= N; i++) cout << dist[i] << " \n"[i == N];
	cout << ans << endl;
	return 0;
}
0