結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー suzuken_wsuzuken_w
提出日時 2021-06-12 04:06:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 310 ms / 3,000 ms
コード長 2,262 bytes
コンパイル時間 4,905 ms
コンパイル使用メモリ 235,452 KB
実行使用メモリ 35,500 KB
最終ジャッジ日時 2023-08-21 18:39:25
合計ジャッジ時間 20,230 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 84 ms
16,996 KB
testcase_05 AC 287 ms
32,912 KB
testcase_06 AC 100 ms
15,836 KB
testcase_07 AC 123 ms
18,368 KB
testcase_08 AC 276 ms
24,168 KB
testcase_09 AC 137 ms
14,240 KB
testcase_10 AC 90 ms
14,552 KB
testcase_11 AC 145 ms
21,060 KB
testcase_12 AC 243 ms
30,136 KB
testcase_13 AC 64 ms
12,652 KB
testcase_14 AC 78 ms
16,464 KB
testcase_15 AC 23 ms
6,544 KB
testcase_16 AC 100 ms
20,836 KB
testcase_17 AC 78 ms
10,672 KB
testcase_18 AC 310 ms
27,840 KB
testcase_19 AC 129 ms
18,252 KB
testcase_20 AC 62 ms
9,628 KB
testcase_21 AC 150 ms
26,756 KB
testcase_22 AC 156 ms
22,912 KB
testcase_23 AC 228 ms
21,932 KB
testcase_24 AC 8 ms
4,456 KB
testcase_25 AC 5 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 8 ms
4,376 KB
testcase_29 AC 8 ms
4,376 KB
testcase_30 AC 6 ms
4,376 KB
testcase_31 AC 6 ms
4,380 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 8 ms
4,376 KB
testcase_34 AC 5 ms
4,380 KB
testcase_35 AC 14 ms
4,544 KB
testcase_36 AC 11 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 6 ms
4,376 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 4 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 5 ms
4,376 KB
testcase_43 AC 8 ms
4,380 KB
testcase_44 AC 4 ms
4,800 KB
testcase_45 AC 5 ms
6,032 KB
testcase_46 AC 6 ms
4,740 KB
testcase_47 AC 9 ms
6,540 KB
testcase_48 AC 18 ms
10,984 KB
testcase_49 AC 18 ms
7,444 KB
testcase_50 AC 33 ms
10,608 KB
testcase_51 AC 3 ms
4,376 KB
testcase_52 AC 33 ms
10,420 KB
testcase_53 AC 14 ms
8,000 KB
testcase_54 AC 3 ms
4,380 KB
testcase_55 AC 24 ms
9,620 KB
testcase_56 AC 5 ms
5,040 KB
testcase_57 AC 23 ms
7,224 KB
testcase_58 AC 15 ms
7,784 KB
testcase_59 AC 4 ms
4,380 KB
testcase_60 AC 6 ms
5,516 KB
testcase_61 AC 7 ms
4,644 KB
testcase_62 AC 16 ms
6,596 KB
testcase_63 AC 10 ms
4,844 KB
testcase_64 AC 226 ms
35,500 KB
testcase_65 AC 5 ms
4,380 KB
testcase_66 AC 107 ms
33,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
using tp=tuple<ll,int,int>;
int main(){
     int n,s,t,k;
     cin>>n>>s>>t>>k;
     s--;t--;
     V<ll> x(n);
     for(int i=0;i<n;i++)cin>>x[i];
     V<V<P>> dp(k+1,V<P>(n+5,P{inf,inf}));
     ll m;
     cin>>m;
     V<V<P>> g(n);
     map<P,ll> mp;
     for(int i=0;i<m;i++){
           ll a,b,c;
           cin>>a>>b>>c;
           --a;--b;
           g[a].emplace_back(b,c);
           mp[{a,b}]=c;
     }
     dp[1][s]=P(x[s],-1);
     priority_queue<tp,V<tp>,greater<tp>> pq;
     pq.emplace(dp[1][s].fi,1,s);
     while(pq.size()){
            auto [v,tim,cur]=pq.top();
            pq.pop();
            if(dp[tim][cur].fi<v)continue;
            for(auto &[to,cost]:g[cur]){
                      P nxt={cost+x[to]+v,cur};
                      if(chmin(dp[min(k,tim+1)][to],nxt)){
                             pq.emplace(nxt.fi,min(k,tim+1),to);
                      }
            }
    }
     if(dp[k][t].fi>=inf){
         cout<<"Impossible"<<"\n";
         return 0;
     }
     int cur=t,id=k;
     V<int> ans;
     while(cur!=-1){
           ans.emplace_back(cur+1);
           int bfo=cur;
           cur=dp[id][cur].se;
           if(cur==-1)break;
           if(id!=k||dp[id][bfo].fi!=dp[id][cur].fi+x[bfo]+mp[{cur,bfo}]){
           id--;
           }
     }
     cout<<"Possible"<<"\n";
     cout<<dp[k][t].fi<<"\n";
     cout<<ans.size()<<"\n";
     reverse(all(ans));
     print(ans);
}
0