結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー 👑 kmjpkmjp
提出日時 2021-06-12 00:48:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,845 bytes
コンパイル時間 2,790 ms
コンパイル使用メモリ 213,636 KB
実行使用メモリ 165,784 KB
最終ジャッジ日時 2024-05-08 21:35:39
合計ジャッジ時間 22,732 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
38,912 KB
testcase_01 AC 33 ms
38,784 KB
testcase_02 WA -
testcase_03 AC 33 ms
38,784 KB
testcase_04 AC 222 ms
71,808 KB
testcase_05 AC 963 ms
165,504 KB
testcase_06 AC 252 ms
77,184 KB
testcase_07 AC 189 ms
63,360 KB
testcase_08 AC 1,006 ms
149,152 KB
testcase_09 AC 229 ms
70,400 KB
testcase_10 AC 85 ms
44,544 KB
testcase_11 AC 368 ms
96,896 KB
testcase_12 AC 680 ms
137,856 KB
testcase_13 AC 148 ms
58,496 KB
testcase_14 AC 232 ms
75,264 KB
testcase_15 AC 52 ms
41,984 KB
testcase_16 AC 335 ms
91,520 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 271 ms
80,916 KB
testcase_20 AC 205 ms
72,320 KB
testcase_21 AC 360 ms
95,872 KB
testcase_22 AC 181 ms
62,592 KB
testcase_23 AC 192 ms
63,360 KB
testcase_24 AC 56 ms
47,488 KB
testcase_25 AC 70 ms
52,608 KB
testcase_26 AC 34 ms
38,784 KB
testcase_27 AC 46 ms
43,520 KB
testcase_28 AC 93 ms
58,240 KB
testcase_29 AC 75 ms
54,272 KB
testcase_30 AC 66 ms
50,304 KB
testcase_31 AC 68 ms
51,456 KB
testcase_32 AC 44 ms
44,032 KB
testcase_33 AC 91 ms
57,344 KB
testcase_34 AC 73 ms
52,736 KB
testcase_35 AC 271 ms
98,816 KB
testcase_36 AC 199 ms
83,200 KB
testcase_37 AC 37 ms
40,960 KB
testcase_38 AC 107 ms
59,264 KB
testcase_39 AC 41 ms
41,728 KB
testcase_40 AC 52 ms
46,208 KB
testcase_41 AC 36 ms
40,064 KB
testcase_42 AC 63 ms
49,664 KB
testcase_43 AC 75 ms
53,248 KB
testcase_44 AC 36 ms
39,680 KB
testcase_45 AC 34 ms
40,192 KB
testcase_46 AC 61 ms
50,176 KB
testcase_47 AC 77 ms
58,240 KB
testcase_48 AC 84 ms
61,568 KB
testcase_49 AC 153 ms
78,592 KB
testcase_50 AC 249 ms
101,504 KB
testcase_51 AC 42 ms
41,984 KB
testcase_52 AC 469 ms
145,024 KB
testcase_53 AC 107 ms
70,272 KB
testcase_54 AC 49 ms
44,416 KB
testcase_55 AC 312 ms
110,720 KB
testcase_56 AC 36 ms
39,936 KB
testcase_57 AC 244 ms
93,824 KB
testcase_58 AC 142 ms
83,840 KB
testcase_59 AC 44 ms
44,160 KB
testcase_60 AC 42 ms
43,776 KB
testcase_61 AC 85 ms
55,040 KB
testcase_62 AC 232 ms
88,960 KB
testcase_63 AC 107 ms
60,800 KB
testcase_64 AC 657 ms
165,784 KB
testcase_65 AC 47 ms
43,088 KB
testcase_66 AC 280 ms
110,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
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;}
//-------------------------------------------------------

int N,S,T,K,M;
int X[101010];
int A[101010],B[101010];
vector<vector<int>> E[1505050];
ll dp[2020202];
int from[2020202];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>S>>T>>K;
	S--,T--;
	FOR(i,N) cin>>X[i];
	cin>>M;
	FOR(i,M) {
		cin>>x>>y>>k;
		x--,y--;
		FOR(j,K-1) {
			E[N*j+x].push_back({N*(j+1)+y,i,X[y]+k});
		}
		E[N*(K-1)+x].push_back({N*(K-1)+y,i,X[y]+k});
	}
	FOR(i,N*K) dp[i]=1LL<<60;
	priority_queue<pair<ll,int>> Q;
	dp[S]=X[S];
	Q.push({-X[S],S});
	while(Q.size()) {
		ll co=-Q.top().first;
		int cur=Q.top().second;
		Q.pop();
		if(dp[cur]!=co) continue;
		FORR(e,E[cur]) if(dp[e[0]]>co+e[2]) {
			dp[e[0]]=co+e[2];
			from[e[0]]=cur;
			Q.push({-dp[e[0]],e[0]});
		}
	}
	
	if(dp[N*(K-1)+T]==1LL<<60) {
		cout<<"Impossible"<<endl;
	}
	else {
		cout<<"Possible"<<endl;
		cout<<dp[N*(K-1)+T]<<endl;
		int cur=N*(K-1)+T;
		vector<int> V;
		while(cur>=N) {
			V.push_back(cur);
			cur=from[cur];
		}
		V.push_back(cur);
		reverse(ALL(V));
		cout<<V.size()<<endl;
		FORR(v,V) cout<<(v%N+1)<<" ";
		cout<<endl;
		
	}
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0