結果
| 問題 |
No.2321 Continuous Flip
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-08-27 13:20:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 277 ms / 2,000 ms |
| コード長 | 1,058 bytes |
| コンパイル時間 | 1,510 ms |
| コンパイル使用メモリ | 170,780 KB |
| 実行使用メモリ | 42,556 KB |
| 最終ジャッジ日時 | 2025-08-27 13:20:48 |
| 合計ジャッジ時間 | 10,554 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
#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;
};
vector<node> G[200005];
priority_queue<pair<int, int>> q;
int SPFA(int s, int t){
memset(dis, 0x3f, sizeof dis);
memset(vis, 0, sizeof vis);
dis[s] = 0;
q.push({0, s});
while (!q.empty()){
auto tmp = q.top();
q.pop();
int u = tmp.second;
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({-dis[v.v], 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;
}
vjudge1