結果
問題 | No.2321 Continuous Flip |
ユーザー | kotatsugame |
提出日時 | 2023-05-26 22:51:48 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 244 ms / 2,000 ms |
コード長 | 867 bytes |
コンパイル時間 | 924 ms |
コンパイル使用メモリ | 79,408 KB |
実行使用メモリ | 31,292 KB |
最終ジャッジ日時 | 2024-12-25 09:33:46 |
合計ジャッジ時間 | 8,562 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include<iostream> #include<vector> #include<queue> using namespace std; int N,M,C; int A[2<<17]; vector<pair<int,int> >G[2<<17]; long dp[2<<17]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin>>N>>M>>C; long sum=0; for(int i=0;i<N;i++) { cin>>A[i]; G[i].push_back(make_pair(i+1,A[i])); G[i+1].push_back(make_pair(i,A[i])); sum+=A[i]; } for(int i=0;i<M;i++) { int l,r;cin>>l>>r; l--; G[l].push_back(make_pair(r,C)); G[r].push_back(make_pair(l,C)); } for(int i=1;i<=N;i++)dp[i]=9e18; priority_queue<pair<long,int> >Q; Q.push(make_pair(0L,0)); while(!Q.empty()) { int u=Q.top().second; long c=-Q.top().first; Q.pop(); if(dp[u]<c)continue; for(pair<int,int>e:G[u]) { int v=e.first; long nc=c+e.second; if(dp[v]>nc) { dp[v]=nc; Q.push(make_pair(-nc,v)); } } } cout<<sum-dp[N]<<endl; }