結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2024-03-09 05:07:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 5,000 ms |
コード長 | 609 bytes |
コンパイル時間 | 1,828 ms |
コンパイル使用メモリ | 199,688 KB |
最終ジャッジ日時 | 2025-02-20 03:24:19 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int n; cin>>n; queue<pair<int,int>> q; q.push(make_pair(1,1)); vector<int> vec(11000,0); vec.at(1)=1; while(!q.empty()){ int now=q.front().first; int num=q.front().second; q.pop(); if(now==n){ cout<<num<<endl; exit(0); } int a=__builtin_popcount(now); if(now+a<=n && vec.at(now+a)==0){ vec.at(now+a)=1; q.push(make_pair(now+a,num+1)); } if(now-a>0 && vec.at(now-a)==0){ vec.at(now-a)=1; q.push(make_pair(now-a,num+1)); } } cout<<-1<<endl; }