結果
| 問題 |
No.3 ビットすごろく
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-11 13:03:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 965 bytes |
| コンパイル時間 | 1,593 ms |
| コンパイル使用メモリ | 177,712 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-01 07:17:26 |
| 合計ジャッジ時間 | 2,555 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 WA * 22 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18;
int main(){
int n;cin >> n;
vector<ll> d(n+1,INF);
vector<vector<int>> g(n+1);
for(int i=1;i<=n;i++){
int cnt=0;
for(int j=0;j<5;j++){
if((i>>j)&1){
cnt++;
}
}
if(i-cnt>=1){
g[i].push_back(i-cnt);
}
if(i+cnt<=n){
g[i].push_back(i+cnt);
}
}
priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> pq;
d[1]=1;
pq.push({0,1});
while(!pq.empty()){
ll u=pq.top().first,v=pq.top().second;
pq.pop();
if(d[v]<u){
continue;
}
for(auto x:g[v]){
if(d[x]>d[v]+1){
d[x]=d[v]+1;
pq.push({d[x],x});
}
}
}
if(d[n]==INF){
cout << -1 << endl;
}
else{
cout << d[n] << endl;
}
}