結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
cleasky
|
| 提出日時 | 2023-06-04 02:10:12 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 644 bytes |
| コンパイル時間 | 2,426 ms |
| コンパイル使用メモリ | 197,664 KB |
| 最終ジャッジ日時 | 2025-02-13 22:31:56 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main()
{
cin.tie(0)->sync_with_stdio(0);
int N;
cin >> N;
vector<int> dp(N + 1, -1);
dp[1] = 1;
queue<int> q;
q.push(__builtin_popcount(1));
int dx[2] = { 1, -1 };
while (not q.empty()) {
int cur = q.front();
int step = __builtin_popcount(q.front());
q.pop();
for (int k : dx) {
int nxt = cur + step * k;
if (nxt >= 1 and nxt <= N and dp[nxt] == -1) {
q.push(nxt);
dp[nxt] = dp[cur] + 1;
}
}
}
cout << dp[N] << endl;
return 0;
}
cleasky