結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-07-29 00:24:58 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 876 bytes |
| コンパイル時間 | 1,982 ms |
| コンパイル使用メモリ | 199,520 KB |
| 最終ジャッジ日時 | 2025-02-23 19:23:13 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define bit(n, k) ((n >> k) & 1)
typedef long long ll;
typedef pair<int, int> pii;
void test_case(int tt){
int n; cin>>n;
vector<int> a(n+1,1e9);
queue<pii> que;
que.emplace(1,1);
a[1]=1;
while (!que.empty())
{
auto cur=que.front(); que.pop();
int cx=cur.first, d=cur.second;
int move=__builtin_popcount(cx);
vector<int> v={cx+move,cx-move};
for(int nx:v){
if(nx>0 && nx<=n && d+1<a[nx]){
que.emplace(nx,d+1);
a[nx]=d+1;
}
}
}
if(a[n]!=1e9)cout<<a[n]<<"\n";
else cout<<"-1\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
//cin>>t;
rep(i, 1, t + 1)
{
test_case(i);
}
}