結果
問題 | No.3 ビットすごろく |
ユーザー |
![]() |
提出日時 | 2024-11-17 02:19:20 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 842 bytes |
コンパイル時間 | 3,130 ms |
コンパイル使用メモリ | 250,220 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-17 02:19:37 |
合計ジャッジ時間 | 4,146 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 WA * 19 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<vector<int>> G(N); for (unsigned int i = 1; i <= N; i++) { int bit_count = popcount(i); int pre = i - bit_count; int next = i + bit_count; if (pre >= 1) { G[i - 1].push_back(pre - 1); } if (next <= N) { G[i - 1].push_back(next - 1); } } vector<bool> visited(N); auto dfs = [&](auto dfs, int v, int ans = 0) { ans++; if (v == N - 1) { cout << ans; exit(0); } if (visited[v]) { return; } visited[v] = true; for (auto nv : G[v]) { dfs(dfs, nv, ans); } }; dfs(dfs, 0); cout << -1; }