結果

問題 No.2321 Continuous Flip
ユーザー kotatsugamekotatsugame
提出日時 2023-05-26 22:51:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 287 ms / 2,000 ms
コード長 867 bytes
コンパイル時間 746 ms
コンパイル使用メモリ 79,020 KB
実行使用メモリ 32,860 KB
最終ジャッジ日時 2023-08-26 13:08:27
合計ジャッジ時間 10,343 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,524 KB
testcase_01 AC 4 ms
9,548 KB
testcase_02 AC 3 ms
9,584 KB
testcase_03 AC 3 ms
9,588 KB
testcase_04 AC 281 ms
26,760 KB
testcase_05 AC 286 ms
26,748 KB
testcase_06 AC 278 ms
26,720 KB
testcase_07 AC 278 ms
26,660 KB
testcase_08 AC 286 ms
26,716 KB
testcase_09 AC 281 ms
26,956 KB
testcase_10 AC 277 ms
26,788 KB
testcase_11 AC 278 ms
26,768 KB
testcase_12 AC 276 ms
26,804 KB
testcase_13 AC 279 ms
26,744 KB
testcase_14 AC 276 ms
26,644 KB
testcase_15 AC 284 ms
26,652 KB
testcase_16 AC 275 ms
26,656 KB
testcase_17 AC 279 ms
26,684 KB
testcase_18 AC 274 ms
26,760 KB
testcase_19 AC 275 ms
26,672 KB
testcase_20 AC 285 ms
26,728 KB
testcase_21 AC 280 ms
26,824 KB
testcase_22 AC 287 ms
26,600 KB
testcase_23 AC 279 ms
26,612 KB
testcase_24 AC 101 ms
21,392 KB
testcase_25 AC 3 ms
9,576 KB
testcase_26 AC 87 ms
20,884 KB
testcase_27 AC 96 ms
22,660 KB
testcase_28 AC 212 ms
32,592 KB
testcase_29 AC 204 ms
31,672 KB
testcase_30 AC 212 ms
32,224 KB
testcase_31 AC 204 ms
32,860 KB
testcase_32 AC 207 ms
32,600 KB
testcase_33 AC 209 ms
31,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int N,M,C;
int A[2<<17];
vector<pair<int,int> >G[2<<17];
long dp[2<<17];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N>>M>>C;
	long sum=0;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		G[i].push_back(make_pair(i+1,A[i]));
		G[i+1].push_back(make_pair(i,A[i]));
		sum+=A[i];
	}
	for(int i=0;i<M;i++)
	{
		int l,r;cin>>l>>r;
		l--;
		G[l].push_back(make_pair(r,C));
		G[r].push_back(make_pair(l,C));
	}
	for(int i=1;i<=N;i++)dp[i]=9e18;
	priority_queue<pair<long,int> >Q;
	Q.push(make_pair(0L,0));
	while(!Q.empty())
	{
		int u=Q.top().second;
		long c=-Q.top().first;
		Q.pop();
		if(dp[u]<c)continue;
		for(pair<int,int>e:G[u])
		{
			int v=e.first;
			long nc=c+e.second;
			if(dp[v]>nc)
			{
				dp[v]=nc;
				Q.push(make_pair(-nc,v));
			}
		}
	}
	cout<<sum-dp[N]<<endl;
}
0