結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー 👑 kmjpkmjp
提出日時 2021-06-12 00:50:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,103 ms / 3,000 ms
コード長 1,843 bytes
コンパイル時間 2,583 ms
コンパイル使用メモリ 212,076 KB
実行使用メモリ 172,136 KB
最終ジャッジ日時 2023-08-21 16:06:16
合計ジャッジ時間 24,664 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
42,380 KB
testcase_01 AC 16 ms
42,276 KB
testcase_02 AC 16 ms
42,340 KB
testcase_03 AC 16 ms
42,276 KB
testcase_04 AC 220 ms
76,672 KB
testcase_05 AC 865 ms
172,136 KB
testcase_06 AC 260 ms
80,776 KB
testcase_07 AC 187 ms
67,004 KB
testcase_08 AC 1,103 ms
153,484 KB
testcase_09 AC 247 ms
73,676 KB
testcase_10 AC 69 ms
49,528 KB
testcase_11 AC 384 ms
102,072 KB
testcase_12 AC 668 ms
143,588 KB
testcase_13 AC 139 ms
62,836 KB
testcase_14 AC 226 ms
80,084 KB
testcase_15 AC 38 ms
45,236 KB
testcase_16 AC 331 ms
95,104 KB
testcase_17 AC 55 ms
47,764 KB
testcase_18 AC 182 ms
57,268 KB
testcase_19 AC 291 ms
84,824 KB
testcase_20 AC 247 ms
75,840 KB
testcase_21 AC 355 ms
102,448 KB
testcase_22 AC 175 ms
65,924 KB
testcase_23 AC 197 ms
66,652 KB
testcase_24 AC 41 ms
50,932 KB
testcase_25 AC 58 ms
56,100 KB
testcase_26 AC 16 ms
42,436 KB
testcase_27 AC 32 ms
46,904 KB
testcase_28 AC 90 ms
61,724 KB
testcase_29 AC 68 ms
57,908 KB
testcase_30 AC 57 ms
53,884 KB
testcase_31 AC 62 ms
54,840 KB
testcase_32 AC 32 ms
47,644 KB
testcase_33 AC 87 ms
60,868 KB
testcase_34 AC 61 ms
56,304 KB
testcase_35 AC 285 ms
102,328 KB
testcase_36 AC 203 ms
86,572 KB
testcase_37 AC 21 ms
44,828 KB
testcase_38 AC 97 ms
62,796 KB
testcase_39 AC 24 ms
45,336 KB
testcase_40 AC 38 ms
50,056 KB
testcase_41 AC 20 ms
43,588 KB
testcase_42 AC 52 ms
53,176 KB
testcase_43 AC 70 ms
57,020 KB
testcase_44 AC 19 ms
43,156 KB
testcase_45 AC 18 ms
45,028 KB
testcase_46 AC 44 ms
55,660 KB
testcase_47 AC 65 ms
63,284 KB
testcase_48 AC 72 ms
65,408 KB
testcase_49 AC 154 ms
83,488 KB
testcase_50 AC 253 ms
105,356 KB
testcase_51 AC 26 ms
45,636 KB
testcase_52 AC 472 ms
148,848 KB
testcase_53 AC 98 ms
74,848 KB
testcase_54 AC 34 ms
47,920 KB
testcase_55 AC 306 ms
114,596 KB
testcase_56 AC 19 ms
43,288 KB
testcase_57 AC 239 ms
98,336 KB
testcase_58 AC 144 ms
88,456 KB
testcase_59 AC 28 ms
47,704 KB
testcase_60 AC 27 ms
49,104 KB
testcase_61 AC 79 ms
60,436 KB
testcase_62 AC 236 ms
93,780 KB
testcase_63 AC 106 ms
66,076 KB
testcase_64 AC 655 ms
170,116 KB
testcase_65 AC 31 ms
46,556 KB
testcase_66 AC 270 ms
115,832 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!=S) {
			V.push_back(cur);
			cur=from[cur];
		}
		V.push_back(S);
		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