結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-09-27 13:54:49 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 771 bytes |
| コンパイル時間 | 3,331 ms |
| コンパイル使用メモリ | 251,648 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-27 13:54:54 |
| 合計ジャッジ時間 | 4,727 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include <bits/stdc++.h>
using i64 = long long;
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int n;
std::cin >> n;
constexpr i64 inf = std::numeric_limits<int>::max();
std::vector<i64> dp(n + 1, inf);
dp[0] = 1;
std::queue<i64> q;
q.push(0);
while (q.size()) {
int d = q.front();
q.pop();
auto e = __builtin_popcount(d + 1);
if (e + d < n && dp[e + d] == inf) {
dp[d + e] = std::min(dp[e + d], dp[d] + 1);
q.push(e + d);
}
if (d - e >= 0 && dp[d - e] == inf) {
dp[d - e] = std::min(dp[d - e], dp[d] + 1);
q.push(d - e);
}
}
std::cout << (dp[n - 1] == inf ? -1 : dp[n - 1]) << '\n';
return 0;
}