結果
| 問題 |
No.2321 Continuous Flip
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-08-01 21:02:14 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 261 ms / 2,000 ms |
| コード長 | 746 bytes |
| コンパイル時間 | 1,759 ms |
| コンパイル使用メモリ | 205,464 KB |
| 実行使用メモリ | 30,760 KB |
| 最終ジャッジ日時 | 2025-08-01 21:02:30 |
| 合計ジャッジ時間 | 11,953 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n,m,C,a[N];
ll d[N];
bool v[N];
vector<pair<int,int>>e[N];
void Addedge(int x,int y,int w) {e[x].emplace_back(y,w),e[y].emplace_back(x,w);}
signed main()
{
ios::sync_with_stdio(0),cin.tie(0);
cin>>n>>m>>C;
ll sum=0;
for(int i=1,a;i<=n;i++) cin>>a,sum+=a,Addedge(i,i+1,a);
for(int i=1,l,r;i<=m;i++) cin>>l>>r,Addedge(l,r+1,C);
priority_queue<pair<ll,int>>pq;
memset(d,0x3f,sizeof(d)),d[1]=0,pq.emplace(0,1);
while(!pq.empty())
{
int x=pq.top().second; pq.pop();
if(v[x]) continue;
v[x]=1;
for(auto it:e[x])
{
int y,w; tie(y,w)=it;
if(!v[y]&&d[x]+w<d[y]) d[y]=d[x]+w,pq.emplace(-d[y],y);
}
}
cout<<sum-d[n+1]<<"\n";
return 0;
}