結果

問題 No.2321 Continuous Flip
ユーザー vjudge1
提出日時 2025-08-27 12:33:26
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,147 bytes
コンパイル時間 1,663 ms
コンパイル使用メモリ 170,480 KB
実行使用メモリ 38,072 KB
最終ジャッジ日時 2025-08-27 12:33:37
合計ジャッジ時間 9,240 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 4
other WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
int c, t, n, m, w, sum;
int a[200005];
int dis[200005], vis[200005];
struct node{
	int v, w;
};
struct node2{
	int u;
	bool operator < (node2 b) const{
		return dis[this->u] > dis[b.u];
	}
};
vector<node> G[200005];
priority_queue<node2> q;
int SPFA(int s, int t){
	memset(dis, 0x3f, sizeof dis);
	memset(vis, 0, sizeof vis);
	dis[s] = 0;
    vis[s] = 1;
	q.push({s});
	while (!q.empty()){
		node2 tmp = q.top();
		q.pop();
		int u = tmp.u;
		if (vis[u])
			continue;
		vis[u] = 1; 
		for (node v : G[u])
			if (dis[u] + v.w < dis[v.v]){
				dis[v.v] = dis[u] + v.w;
				q.push({v.v});
			}
	}
	return dis[t];
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin >> n >> m >> c;
	sum = 0;
	for (int i = 1; i <= n; i++){
		G[i].clear();
		cin >> a[i];
		sum += a[i];
	}
	G[n + 1].clear();
	for (int i = 1; i <= n; i++){
		G[i].push_back({i + 1, a[i]});
		G[i + 1].push_back({i, a[i]});
	}
	for (int i = 1; i <= m; i++){
		int l, r;
		cin >> l >> r;
		G[l].push_back({r + 1, c}); 
		G[r + 1].push_back({l, c}); 
	}
	cout << sum - SPFA(1, n + 1);
	return 0;
}
0