結果

問題 No.2321 Continuous Flip
ユーザー t98slidert98slider
提出日時 2023-05-27 06:41:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 342 ms / 2,000 ms
コード長 1,073 bytes
コンパイル時間 1,759 ms
コンパイル使用メモリ 181,640 KB
実行使用メモリ 41,992 KB
最終ジャッジ日時 2023-08-26 17:17:46
合計ジャッジ時間 13,512 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 331 ms
35,092 KB
testcase_05 AC 323 ms
35,020 KB
testcase_06 AC 342 ms
35,172 KB
testcase_07 AC 323 ms
35,024 KB
testcase_08 AC 330 ms
35,240 KB
testcase_09 AC 327 ms
35,104 KB
testcase_10 AC 323 ms
35,088 KB
testcase_11 AC 318 ms
35,064 KB
testcase_12 AC 328 ms
35,120 KB
testcase_13 AC 329 ms
35,084 KB
testcase_14 AC 330 ms
35,108 KB
testcase_15 AC 338 ms
35,160 KB
testcase_16 AC 333 ms
35,160 KB
testcase_17 AC 322 ms
35,124 KB
testcase_18 AC 325 ms
35,084 KB
testcase_19 AC 332 ms
35,184 KB
testcase_20 AC 334 ms
35,152 KB
testcase_21 AC 326 ms
35,128 KB
testcase_22 AC 330 ms
35,116 KB
testcase_23 AC 327 ms
35,024 KB
testcase_24 AC 103 ms
27,156 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 92 ms
30,660 KB
testcase_27 AC 100 ms
29,936 KB
testcase_28 AC 222 ms
41,340 KB
testcase_29 AC 222 ms
41,824 KB
testcase_30 AC 229 ms
41,476 KB
testcase_31 AC 221 ms
41,588 KB
testcase_32 AC 231 ms
41,992 KB
testcase_33 AC 226 ms
41,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, c, v, u, L, R;
    ll d, w;
    cin >> n >> m >> c;
    vector<vector<pair<int, ll>>> g(n + 1);
    vector<int> a(n);
    vector<ll> as(n + 1), dist(n + 1, 1ll << 60);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        as[i + 1] = as[i] + a[i];
        g[i].emplace_back(i + 1, a[i]);
        g[i + 1].emplace_back(i, a[i]);
    }
    for(int i = 0; i < m; i++){
        cin >> L >> R;
        L--;
        g[L].emplace_back(R, c);
        g[R].emplace_back(L, c);
    }
    priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq;
    dist[0] = 0;
    pq.emplace(0, 0);
    while(!pq.empty()){
        tie(d, v) = pq.top();
        pq.pop();
        if(d > dist[v]) continue;
        for(auto &&pa : g[v]){
            tie(u, w) = pa;
            if(d + w >= dist[u]) continue;
            dist[u] = d + w;
            pq.emplace(dist[u], u);
        }
    }
    cout << as[n] - dist[n] << '\n';
}
0