結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-22 16:35:12 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 368 bytes |
| コンパイル時間 | 2,600 ms |
| コンパイル使用メモリ | 250,076 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-09-30 10:37:12 |
| 合計ジャッジ時間 | 3,639 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;cin>>n;vector<int> A(n+1,-1);queue<pair<int,int>> Q;Q.push({1,1});
while(!Q.empty()){
auto[x,y]=Q.front();Q.pop();
if(A[x]==-1){
A[x]=y;
if(x==n)break;
int z=__builtin_popcount(x);
if(x-z>0)Q.push({x-z,y+1});
if(x+z<=n)Q.push({x+z,y+1});
}
}
cout<<A[n];
}