結果
| 問題 |
No.3 ビットすごろく
|
| ユーザー |
|
| 提出日時 | 2021-07-17 15:35:42 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 643 bytes |
| コンパイル時間 | 671 ms |
| コンパイル使用メモリ | 70,312 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-07 03:24:28 |
| 合計ジャッジ時間 | 1,462 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 WA * 15 |
ソースコード
#include <iostream>
#include <vector>
// #include <bits/stdc++.h>
using namespace std;
#define INF 10000000
void next(int k, vector<int> &dp, int count, int n) {
int step = 0;
if (dp[k] < INF)
return;
dp[k] = count;
count++;
for (int i = k; i > 0; i = i >> 1) {
if(i & 1) step++;
}
if (k + step <= n)
next(k + step, dp, count, n);
if (k - step >= 1)
next(k - step, dp, count, n);
}
int main() {
int n;
cin >> n;
vector<int> dp(n+1, INF);
int count = 1;
next(1, dp, 1, n);
if (dp.at(n) < INF)
cout << dp.at(n) << endl;
else
cout << -1 << endl;
return 0;
}