結果

問題 No.3 ビットすごろく
ユーザー recososorecososo
提出日時 2020-02-11 13:03:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 965 bytes
コンパイル時間 2,011 ms
コンパイル使用メモリ 178,404 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 14:36:58
合計ジャッジ時間 3,200 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 3 ms
6,676 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 3 ms
6,676 KB
testcase_13 WA -
testcase_14 AC 3 ms
6,676 KB
testcase_15 AC 3 ms
6,676 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1 ms
6,676 KB
testcase_22 AC 4 ms
6,676 KB
testcase_23 AC 3 ms
6,676 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
6,676 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    }
}
0