結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-02-05 19:36:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 15 ms / 5,000 ms |
| コード長 | 815 bytes |
| コンパイル時間 | 3,733 ms |
| コンパイル使用メモリ | 163,124 KB |
| 最終ジャッジ日時 | 2025-01-27 20:32:38 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <cstring>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < int(n);i++)
int main(){
int n;
cin >> n;
vector<int> d(10032,1 << 30);
queue<int> q;
q.push(1);
d[1] = 0;
while(!q.empty()){
int x = q.front(); q.pop();
int add = __builtin_popcount(x);
if (x + add <= n && d[x + add] == 1 << 30){
d[x+add] = d[x]+1;
q.push(x+add);
}
if (0 < x-add && d[x-add] == 1 << 30){
d[x-add] = d[x] + 1;
q.push(x-add);
}
}
if (d[n] == 1 << 30) cout << -1 << endl;
else cout << d[n] + 1 << endl;
return 0;
}