結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-02 00:33:07 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 758 bytes |
| コンパイル時間 | 1,684 ms |
| コンパイル使用メモリ | 172,292 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-01 09:42:42 |
| 合計ジャッジ時間 | 2,549 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int n;
cin >> n;
vector<int> counts(n, 0);
vector<int> moves(n, -1);
rep(i, n) {
rep(j, 14) counts[i] += ((i+1) >> j) % 2;
}
moves[0] = 1;
deque<int> pos;
pos.push_back(0);
while (pos.size() > 0) {
int val = pos.at(0);
pos.pop_front();
int f = val + counts[val];
int b = val - counts[val];
if(f < n && moves[f] == -1) {
moves[f] = moves[val] + 1;
pos.push_back(f);
}
if(b >= 0 && moves[b] == -1) {
moves[b] = moves[val] + 1;
pos.push_back(b);
}
}
cout << moves[n-1] << endl;
}