結果
| 問題 | No.3 ビットすごろく |
| コンテスト | |
| ユーザー |
kazuppa
|
| 提出日時 | 2024-07-29 12:23:28 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 1 ms / 5,000 ms |
| + 568µs | |
| コード長 | 793 bytes |
| 記録 | |
| コンパイル時間 | 2,335 ms |
| コンパイル使用メモリ | 336,580 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-08-24 17:31:24 |
| 合計ジャッジ時間 | 4,481 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 33 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin>>n;
//dist[i]=移動手数
//現段階で行けないときは-1
vector<int> dist(n+1,-1);
dist[1]=1;
queue<int> que;
que.push(1);
while(!que.empty()){
int u=que.front();que.pop();
//ここからは遷移
//bit.count()=bitの桁が1になっている数==__builtinpop.count
//uから1手で行けるのはu+bit.count()かu-bit.count()
if(u+__builtin_popcount(u)<=n&&dist[u+__builtin_popcount(u)]==-1){
dist[u+__builtin_popcount(u)]=dist[u]+1;
que.push(u+__builtin_popcount(u));
}
if(u-__builtin_popcount(u)>0&&dist[u-__builtin_popcount(u)]==-1){
dist[u-__builtin_popcount(u)]=dist[u]+1;
que.push(u-__builtin_popcount(u));
}
}
cout<<dist[n]<<endl;
}
kazuppa