結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー KKT89KKT89
提出日時 2021-06-12 03:28:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 166 ms / 3,000 ms
コード長 1,951 bytes
コンパイル時間 7,039 ms
コンパイル使用メモリ 291,152 KB
実行使用メモリ 33,756 KB
最終ジャッジ日時 2023-08-21 18:18:57
合計ジャッジ時間 21,894 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 46 ms
15,172 KB
testcase_05 AC 164 ms
24,436 KB
testcase_06 AC 63 ms
12,884 KB
testcase_07 AC 73 ms
17,168 KB
testcase_08 AC 119 ms
13,412 KB
testcase_09 AC 43 ms
7,412 KB
testcase_10 AC 56 ms
16,560 KB
testcase_11 AC 84 ms
15,968 KB
testcase_12 AC 136 ms
21,600 KB
testcase_13 AC 42 ms
10,312 KB
testcase_14 AC 48 ms
14,444 KB
testcase_15 AC 17 ms
6,216 KB
testcase_16 AC 65 ms
19,644 KB
testcase_17 AC 28 ms
5,824 KB
testcase_18 AC 166 ms
22,688 KB
testcase_19 AC 75 ms
13,376 KB
testcase_20 AC 28 ms
5,800 KB
testcase_21 AC 82 ms
25,272 KB
testcase_22 AC 81 ms
20,272 KB
testcase_23 AC 85 ms
10,472 KB
testcase_24 AC 5 ms
4,380 KB
testcase_25 AC 4 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 5 ms
4,376 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 4 ms
4,376 KB
testcase_31 AC 5 ms
4,376 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 6 ms
4,380 KB
testcase_34 AC 5 ms
4,380 KB
testcase_35 AC 10 ms
4,380 KB
testcase_36 AC 9 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 5 ms
4,376 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 3 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 4 ms
4,380 KB
testcase_43 AC 5 ms
4,376 KB
testcase_44 AC 3 ms
4,380 KB
testcase_45 AC 2 ms
4,768 KB
testcase_46 AC 5 ms
4,376 KB
testcase_47 AC 7 ms
4,548 KB
testcase_48 AC 11 ms
7,364 KB
testcase_49 AC 12 ms
5,424 KB
testcase_50 AC 27 ms
7,280 KB
testcase_51 AC 3 ms
4,376 KB
testcase_52 AC 27 ms
7,392 KB
testcase_53 AC 10 ms
5,172 KB
testcase_54 AC 2 ms
4,380 KB
testcase_55 AC 18 ms
6,920 KB
testcase_56 AC 3 ms
4,380 KB
testcase_57 AC 20 ms
5,556 KB
testcase_58 AC 10 ms
5,292 KB
testcase_59 AC 3 ms
4,376 KB
testcase_60 AC 4 ms
4,376 KB
testcase_61 AC 5 ms
4,376 KB
testcase_62 AC 11 ms
4,904 KB
testcase_63 AC 8 ms
4,380 KB
testcase_64 AC 156 ms
24,900 KB
testcase_65 AC 5 ms
4,380 KB
testcase_66 AC 78 ms
33,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,s,t,k; cin >> n >> s >> t >> k;
    s--; t--;
    vector<ll> x(n);
    for(int i=0;i<n;i++){
        cin >> x[i];
    }
    vector<vector<pair<int,ll>>> g(n);
    int m; cin >> m;
    for(int i=0;i<m;i++){
        int a,b,y; cin >> a >> b >> y;
        a--; b--;
        g[a].push_back({b,y});
    } 
    const ll INF=1e18;
    vector<vector<ll>> d(n,vector<ll>(k,INF));
    vector<vector<pair<int,int>>> rev(n,vector<pair<int,int>>(k,{-1,-1})); 
    d[s][0]=x[s];
    priority_queue<pair<ll,pair<int,int>>,vector<pair<ll,pair<int,int>>>,greater<pair<ll,pair<int,int>>>> pq;
    pq.push({d[s][0],{s,0}});
    while(pq.size()){
        auto p=pq.top(); pq.pop();
        int ss=p.second.first,cn=p.second.second;
        if(p.first!=d[ss][cn])continue;
        for(auto to:g[ss]){
            ll cost=p.first+to.second+x[to.first];
            int nxt=to.first;
            int nxc=min(k-1,cn+1);
            if(cost<d[nxt][nxc]){
                d[nxt][nxc]=cost;
                rev[nxt][nxc]={ss,cn};
                pq.push({d[nxt][nxc],{nxt,nxc}});
            }
        }
    }
    if(d[t][k-1]==INF){
        printf("Impossible\n");
    }
    else{
        printf("Possible\n");
        printf("%lld\n",d[t][k-1]);
        auto p=rev[t][k-1];
        vector<int> v={t};
        while(p.second>=0){
            int nxt=p.first,nxc=p.second;
            v.push_back(nxt);
            p=rev[nxt][nxc];
        }
        reverse(v.begin(), v.end());
        printf("%d\n",v.size());
        for(int i=0;i<v.size();i++){
            printf("%d ",v[i]+1);
        }
        printf("\n");
    }

}
0