結果
問題 | No.3 ビットすごろく |
ユーザー | shinchan |
提出日時 | 2019-03-17 18:48:20 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,471 bytes |
コンパイル時間 | 1,672 ms |
コンパイル使用メモリ | 172,800 KB |
実行使用メモリ | 20,884 KB |
最終ジャッジ日時 | 2023-09-21 20:38:51 |
合計ジャッジ時間 | 16,463 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
20,884 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 10 ms
4,500 KB |
testcase_04 | AC | 3 ms
4,380 KB |
testcase_05 | AC | 171 ms
4,380 KB |
testcase_06 | AC | 12 ms
4,376 KB |
testcase_07 | AC | 5 ms
4,380 KB |
testcase_08 | AC | 56 ms
4,376 KB |
testcase_09 | AC | 1,125 ms
7,712 KB |
testcase_10 | AC | 3,099 ms
12,128 KB |
testcase_11 | AC | 682 ms
7,092 KB |
testcase_12 | AC | 137 ms
4,376 KB |
testcase_13 | AC | 8 ms
4,376 KB |
testcase_14 | AC | 2,581 ms
12,000 KB |
testcase_15 | TLE | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
ソースコード
#include <bits/stdc++.h> #define be(v) (v).begin(),(v).end() #define pb(q) push_back(q) #define era(t) t.erase(unique(be(t)),t.end()) #define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl; typedef long long ll; using namespace std; const ll mod=1000000007,mod9=1000000009; template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));} queue<pair<int,int> > q; vector<pair<bool,int> > v; int ans=1e9; int n; void solve(pair<int,int> p){ int maki=p.first; int num=0; v[p.first]=make_pair(true,p.second); if(p.first==n){ ans=min(ans,p.second); return; } while(maki){ if(maki%2==1){ num++; } maki/=2; } int pm=p.first-num; int pp=p.first+num; p.second++; if(ans>p.second&&pm>0&&!(v[pm].first==true&&v[pm].second<=p.second)){ q.push(make_pair(pm,p.second)); } if(ans>p.second&&pp<=n&&!(v[pp].first==true&&v[pp].second<=p.second)){ q.push(make_pair(pp,p.second)); } return; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin>>n; if(n==1){ cout<<1<<endl; return 0; } for(int i=0;i<=n;i++){ v.pb(make_pair(false,1e9)); } v[1]=make_pair(true,1); q.push(make_pair(1,1)); while(q.size()){ solve(q.front()); q.pop(); } if(v[n].first==true){ cout << ans<<endl; } else{ cout << -1<<endl; } return 0; }