結果

問題 No.2321 Continuous Flip
ユーザー lgswdnlgswdn
提出日時 2023-06-03 14:42:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 306 ms / 2,000 ms
コード長 1,861 bytes
コンパイル時間 2,109 ms
コンパイル使用メモリ 206,488 KB
実行使用メモリ 41,780 KB
最終ジャッジ日時 2023-08-28 07:53:23
合計ジャッジ時間 12,359 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,808 KB
testcase_01 AC 4 ms
9,728 KB
testcase_02 AC 4 ms
9,600 KB
testcase_03 AC 5 ms
9,684 KB
testcase_04 AC 302 ms
34,276 KB
testcase_05 AC 297 ms
34,196 KB
testcase_06 AC 306 ms
34,356 KB
testcase_07 AC 299 ms
34,400 KB
testcase_08 AC 295 ms
34,344 KB
testcase_09 AC 297 ms
34,264 KB
testcase_10 AC 300 ms
34,236 KB
testcase_11 AC 298 ms
34,380 KB
testcase_12 AC 294 ms
34,268 KB
testcase_13 AC 297 ms
34,192 KB
testcase_14 AC 297 ms
34,504 KB
testcase_15 AC 299 ms
34,376 KB
testcase_16 AC 293 ms
34,368 KB
testcase_17 AC 296 ms
34,232 KB
testcase_18 AC 292 ms
34,192 KB
testcase_19 AC 301 ms
34,220 KB
testcase_20 AC 295 ms
34,284 KB
testcase_21 AC 295 ms
34,548 KB
testcase_22 AC 303 ms
34,232 KB
testcase_23 AC 295 ms
34,168 KB
testcase_24 AC 71 ms
26,912 KB
testcase_25 AC 5 ms
9,660 KB
testcase_26 AC 60 ms
26,632 KB
testcase_27 AC 67 ms
29,460 KB
testcase_28 AC 196 ms
41,780 KB
testcase_29 AC 198 ms
41,660 KB
testcase_30 AC 201 ms
41,268 KB
testcase_31 AC 194 ms
41,112 KB
testcase_32 AC 192 ms
41,376 KB
testcase_33 AC 200 ms
40,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x) {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x) {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x) {return (x==0?-1:__builtin_ctzll(x));}

#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define ac 1
#define wa 0
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
  return x*w;
}

const int N=2e5+9,inf=2e18;
int n,m,d[N],ans,c,vst[N];
vp e[N];

void dijkstra() {
  d[1]=0; rep(i,2,n+1) d[i]=inf;
  priority_queue<pii>q; q.push(pii(0,1));
  while(!q.empty()) {
    int u=q.top().se; q.pop();
    if(!vst[u]) vst[u]=1; else continue;
    for(auto [v,w]:e[u]) if(d[v]>d[u]+w)
      d[v]=d[u]+w, q.push(pii(-d[v],v));
  }
}

signed main() {
  n=read(), m=read(), c=read();
  rep(i,1,n) {
    int a=read(); ans+=a;
    e[i].eb(i+1,a), e[i+1].eb(i,a);
  }
  rep(i,1,m) {
    int l=read(), r=read();
    e[l].eb(r+1,c), e[r+1].eb(l,c);
  }
  dijkstra();
  printf("%lld\n",ans-d[n+1]);
  return 0;
}
0