結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
kyomachi_yswr
|
| 提出日時 | 2019-06-16 23:38:46 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 845 bytes |
| コンパイル時間 | 754 ms |
| コンパイル使用メモリ | 89,976 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-01 09:22:44 |
| 合計ジャッジ時間 | 1,770 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>
#include <stack>
using namespace std;
typedef long long ll;
int main() {
int N;
cin >> N;
vector<int> load(N + 1, -1);
queue<int> q;
q.push(1);
load[1] = 1;
while(!q.empty()) {
int p = q.front();
q.pop();
if (p == N) {
break;
}
bitset<14> b(p);
int nf = p + (int)b.count();
if (0 < nf && nf <= N && load[nf] == -1) {
q.push(nf);
load[nf] = load[p] + 1;
}
int nb = p - (int)b.count();
if (0 < nb && nb <= N && load[nb] == -1) {
q.push(nb);
load[nb] = load[p] + 1;
}
}
cout << load[N] << endl;
return 0;
}
kyomachi_yswr