結果

問題 No.2321 Continuous Flip
ユーザー kotatsugamekotatsugame
提出日時 2023-05-26 22:43:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 729 bytes
コンパイル時間 739 ms
コンパイル使用メモリ 77,408 KB
実行使用メモリ 20,172 KB
最終ジャッジ日時 2023-08-26 12:53:44
合計ジャッジ時間 8,209 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
11,760 KB
testcase_01 AC 4 ms
11,628 KB
testcase_02 AC 4 ms
11,588 KB
testcase_03 AC 4 ms
11,612 KB
testcase_04 WA -
testcase_05 AC 165 ms
19,212 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 160 ms
19,320 KB
testcase_22 WA -
testcase_23 AC 162 ms
19,240 KB
testcase_24 AC 81 ms
20,156 KB
testcase_25 AC 4 ms
11,548 KB
testcase_26 AC 67 ms
17,672 KB
testcase_27 AC 91 ms
18,028 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 139 ms
19,976 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 132 ms
19,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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