結果
問題 |
No.3 ビットすごろく
|
ユーザー |
|
提出日時 | 2021-01-19 16:59:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 908 bytes |
コンパイル時間 | 771 ms |
コンパイル使用メモリ | 85,932 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-01 10:02:18 |
合計ジャッジ時間 | 1,785 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
#include<cstdio> #include<cstring> #include<iostream> #include<cmath> #include<string> #include<algorithm> #include<vector> #include<queue> #include<map> using namespace std; typedef long long LL; const int INF=0x3f3f3f3f; const int MAXN=10001; int s2(int x){ int cnt=0; while(x){ if(x&1)cnt++; x >>= 1; } return cnt; } int t[MAXN],d[MAXN]; queue<int> q; int main(){ int n; scanf("%d",&n); for(int i=1;i<=n;i++) { t[i]=s2(i); } memset(d,-1,sizeof(d)); d[1]=1; q.push(1); while(!q.empty()){ int r=q.front();q.pop(); if(r==n){ break; } if(r+t[r]<=n && d[r+t[r]]==-1){ d[r+t[r]]=d[r]+1; q.push(r+t[r]); } if(r-t[r]>=1 && d[r-t[r]]==-1){ d[r-t[r]]=d[r]+1; q.push(r-t[r]); } } printf("%d\n", d[n]); return 0; }