結果

問題 No.1545 [Cherry 2nd Tune N] Anthem
ユーザー kotatsugamekotatsugame
提出日時 2021-06-11 21:50:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 277 ms / 3,000 ms
コード長 1,337 bytes
コンパイル時間 1,210 ms
コンパイル使用メモリ 92,296 KB
実行使用メモリ 26,540 KB
最終ジャッジ日時 2024-05-08 17:30:33
合計ジャッジ時間 12,795 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,528 KB
testcase_01 AC 4 ms
6,528 KB
testcase_02 AC 5 ms
6,528 KB
testcase_03 AC 4 ms
6,656 KB
testcase_04 AC 102 ms
13,568 KB
testcase_05 AC 266 ms
20,096 KB
testcase_06 AC 113 ms
12,128 KB
testcase_07 AC 137 ms
12,712 KB
testcase_08 AC 230 ms
13,520 KB
testcase_09 AC 118 ms
8,576 KB
testcase_10 AC 118 ms
9,780 KB
testcase_11 AC 148 ms
14,044 KB
testcase_12 AC 232 ms
18,296 KB
testcase_13 AC 83 ms
10,184 KB
testcase_14 AC 92 ms
13,696 KB
testcase_15 AC 33 ms
7,552 KB
testcase_16 AC 120 ms
16,616 KB
testcase_17 AC 78 ms
7,680 KB
testcase_18 AC 277 ms
12,816 KB
testcase_19 AC 139 ms
11,988 KB
testcase_20 AC 69 ms
8,064 KB
testcase_21 AC 160 ms
19,564 KB
testcase_22 AC 169 ms
14,692 KB
testcase_23 AC 205 ms
10,368 KB
testcase_24 AC 12 ms
6,784 KB
testcase_25 AC 8 ms
6,656 KB
testcase_26 AC 3 ms
6,528 KB
testcase_27 AC 7 ms
6,784 KB
testcase_28 AC 11 ms
6,784 KB
testcase_29 AC 11 ms
6,784 KB
testcase_30 AC 8 ms
6,656 KB
testcase_31 AC 9 ms
6,784 KB
testcase_32 AC 6 ms
6,784 KB
testcase_33 AC 10 ms
6,784 KB
testcase_34 AC 8 ms
6,656 KB
testcase_35 AC 18 ms
6,912 KB
testcase_36 AC 14 ms
7,040 KB
testcase_37 AC 5 ms
6,656 KB
testcase_38 AC 8 ms
6,912 KB
testcase_39 AC 4 ms
6,656 KB
testcase_40 AC 7 ms
6,784 KB
testcase_41 AC 5 ms
6,784 KB
testcase_42 AC 8 ms
6,912 KB
testcase_43 AC 10 ms
6,784 KB
testcase_44 AC 8 ms
8,320 KB
testcase_45 AC 6 ms
8,960 KB
testcase_46 AC 9 ms
7,680 KB
testcase_47 AC 14 ms
9,216 KB
testcase_48 AC 20 ms
13,440 KB
testcase_49 AC 19 ms
10,376 KB
testcase_50 AC 36 ms
13,692 KB
testcase_51 AC 5 ms
6,784 KB
testcase_52 AC 37 ms
13,696 KB
testcase_53 AC 17 ms
10,692 KB
testcase_54 AC 5 ms
7,040 KB
testcase_55 AC 28 ms
12,928 KB
testcase_56 AC 9 ms
8,576 KB
testcase_57 AC 25 ms
10,112 KB
testcase_58 AC 19 ms
10,752 KB
testcase_59 AC 7 ms
7,424 KB
testcase_60 AC 9 ms
8,420 KB
testcase_61 AC 10 ms
7,680 KB
testcase_62 AC 17 ms
9,732 KB
testcase_63 AC 13 ms
7,936 KB
testcase_64 AC 264 ms
21,404 KB
testcase_65 AC 7 ms
7,016 KB
testcase_66 AC 123 ms
26,540 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
int N,S,T,K,M;
int X[1<<17];
vector<pair<int,int> >G[1<<17];
main()
{
	cin>>N>>S>>T>>K;
	S--,T--;
	K--;
	for(int i=0;i<N;i++)cin>>X[i];
	cin>>M;
	for(int i=0;i<M;i++)
	{
		int a,b,c;cin>>a>>b>>c;
		a--,b--;
		G[a].push_back(make_pair(b,c));
	}
	vector<vector<long> >dp(K+1,vector<long>(N,9e18));
	vector<vector<int> >prc(K+1,vector<int>(N,-1));
	vector<vector<int> >pru(K+1,vector<int>(N,-1));
	dp[0][S]=X[S];
	priority_queue<pair<long,pair<int,int> > >P;
	P.push(make_pair(-X[S],make_pair(0,S)));
	while(!P.empty())
	{
		int c=P.top().second.first;
		int u=P.top().second.second;
		long cost=-P.top().first;
		P.pop();
		if(dp[c][u]<cost)continue;
		for(pair<int,int>e:G[u])
		{
			int v=e.first;
			long nxt=cost+e.second+X[v];
			int nc=c==K?c:c+1;
			if(dp[nc][v]>nxt)
			{
				dp[nc][v]=nxt;
				prc[nc][v]=c;
				pru[nc][v]=u;
				P.push(make_pair(-nxt,make_pair(nc,v)));
			}
		}
	}
	if(dp[K][T]==(long)9e18)
	{
		cout<<"Impossible"<<endl;
		return 0;
	}
	cout<<"Possible"<<endl;
	cout<<dp[K][T]<<endl;
	vector<int>ans;
	while(K!=-1)
	{
		ans.push_back(T);
		int nk=prc[K][T];
		T=pru[K][T];
		K=nk;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans.size()<<endl;
	for(int i=0;i<ans.size();i++)cout<<ans[i]+1<<(i+1==ans.size()?"\n":" ");
}
0