結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-08 06:00:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 653 bytes |
| コンパイル時間 | 1,037 ms |
| コンパイル使用メモリ | 88,656 KB |
| 最終ジャッジ日時 | 2025-01-11 00:06:10 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <numeric>
using namespace std;
typedef long long int ll;
int dp[10001];
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n; cin >> n;
for(int i=0;i<10001;i++){
dp[i]=1e9;
}
dp[1]=1;
queue<int> q;
q.push(1);
while(q.size()){
int qq=q.front(); q.pop();
int p=__builtin_popcount(qq);
if(qq-p>=1&&dp[qq-p]>dp[qq]+1){
dp[qq-p]=dp[qq]+1;
q.push(qq-p);
}
if(qq+p<=n&&dp[qq+p]>dp[qq]+1){
dp[qq+p]=dp[qq]+1;
q.push(qq+p);
}
}
if(dp[n]==1e9)dp[n]=-1;
cout << dp[n] << endl;
}