結果

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

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
int c, t, n, m, 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, -1, sizeof dis);
	memset(vis, 0, sizeof vis);
	dis[s] = 0;
	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] == -1){
				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;
		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, c;
			cin >> l >> r >> c;
			G[l].push_back({r + 1, c}); 
			G[r + 1].push_back({l, c}); 
		}
		cout << sum - SPFA(1, n + 1);
	return 0;
}
0