結果

問題 No.2321 Continuous Flip
ユーザー kotatsugamekotatsugame
提出日時 2023-05-26 22:51:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 266 ms / 2,000 ms
コード長 867 bytes
コンパイル時間 977 ms
コンパイル使用メモリ 79,808 KB
実行使用メモリ 33,560 KB
最終ジャッジ日時 2024-06-07 08:22:58
合計ジャッジ時間 9,828 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,184 KB
testcase_01 AC 4 ms
9,668 KB
testcase_02 AC 4 ms
10,052 KB
testcase_03 AC 4 ms
10,308 KB
testcase_04 AC 227 ms
27,364 KB
testcase_05 AC 222 ms
27,496 KB
testcase_06 AC 218 ms
27,532 KB
testcase_07 AC 223 ms
27,276 KB
testcase_08 AC 228 ms
27,392 KB
testcase_09 AC 238 ms
27,536 KB
testcase_10 AC 238 ms
27,064 KB
testcase_11 AC 239 ms
27,360 KB
testcase_12 AC 252 ms
27,080 KB
testcase_13 AC 233 ms
27,176 KB
testcase_14 AC 233 ms
27,388 KB
testcase_15 AC 240 ms
27,388 KB
testcase_16 AC 229 ms
27,440 KB
testcase_17 AC 266 ms
27,416 KB
testcase_18 AC 224 ms
27,000 KB
testcase_19 AC 232 ms
27,416 KB
testcase_20 AC 230 ms
27,256 KB
testcase_21 AC 231 ms
27,532 KB
testcase_22 AC 247 ms
27,360 KB
testcase_23 AC 235 ms
27,488 KB
testcase_24 AC 99 ms
21,444 KB
testcase_25 AC 4 ms
11,592 KB
testcase_26 AC 87 ms
21,300 KB
testcase_27 AC 90 ms
22,724 KB
testcase_28 AC 181 ms
33,560 KB
testcase_29 AC 179 ms
33,368 KB
testcase_30 AC 184 ms
31,372 KB
testcase_31 AC 174 ms
33,180 KB
testcase_32 AC 175 ms
31,772 KB
testcase_33 AC 186 ms
32,152 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