結果
問題 |
No.2321 Continuous Flip
|
ユーザー |
![]() |
提出日時 | 2023-05-26 22:27:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,461 bytes |
コンパイル時間 | 1,468 ms |
コンパイル使用メモリ | 124,244 KB |
最終ジャッジ日時 | 2025-02-13 07:22:10 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 9 WA * 21 |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } const ll INF = 1e+18; using P = pair<ll, int>; struct edge{ int to; ll cost; edge(int to, ll cost): to(to), cost(cost) {} }; vector<ll> dijkstra(int s, vector<vector<edge>> G){ priority_queue<P, vector<P>, greater<P>> que; int n = G.size(); vector<ll> d(n, INF); d[s] = 0; que.push(P(0, s)); while(!que.empty()){ P p = que.top();que.pop(); int v = p.second; if(d[v] < p.first) continue; for(int i = 0; i < G[v].size(); i++){ edge e = G[v][i]; if(d[v] + e.cost < d[e.to]){ d[e.to] = d[v] + e.cost; que.push(P(d[e.to], e.to)); } } } return d; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n, m; ll c; cin >> n >> m >> c; vector<ll> a(n); for(int i = 0; i < n; i++) cin >> a[i]; vector<vector<edge>> g(n+1); for(int i = 0; i < n; i++){ g[i].push_back(edge(i+1, a[i])); g[i+1].push_back(edge(i, a[i])); } for(int i = 0; i < m; i++){ int l, r; cin >> l >> r; l--; g[l].push_back(edge(r, c)); } ll a_sum = accumulate(a.begin(), a.end(), 0ll); auto d = dijkstra(0, g); cout << a_sum-d[n] << endl; }