結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2020-04-03 22:22:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 660 bytes |
コンパイル時間 | 1,649 ms |
コンパイル使用メモリ | 173,292 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 09:43:58 |
合計ジャッジ時間 | 2,605 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll=long long; #define MOD 1000000007 int main(){ int N; cin>>N; vector<int> count(N+1,0); for(int i=0;i<N+1;i++){ int res=i; while(res>0){ count.at(i)+=res%2; res>>=1; } } vector<int> ans(N+1,-1); queue<int> q; ans.at(1)=1; q.push(1); while(!q.empty()){ int n=q.front(); int x=count.at(n); if(n-x>0){ if(ans.at(n-x)==-1){ ans.at(n-x)=ans.at(n)+1; q.push(n-x); } } if(n+x<=N){ if(ans.at(n+x)==-1){ ans.at(n+x)=ans.at(n)+1; q.push(n+x); } } q.pop(); } cout<<ans.at(N)<<endl; }