結果

問題 No.2321 Continuous Flip
ユーザー 👑 tatyamtatyam
提出日時 2023-02-16 05:27:59
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 372 ms / 2,000 ms
コード長 1,175 bytes
コンパイル時間 4,593 ms
コンパイル使用メモリ 255,632 KB
実行使用メモリ 40,408 KB
最終ジャッジ日時 2023-08-26 09:32:51
合計ジャッジ時間 16,106 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 364 ms
32,796 KB
testcase_05 AC 366 ms
32,724 KB
testcase_06 AC 365 ms
32,804 KB
testcase_07 AC 365 ms
32,804 KB
testcase_08 AC 369 ms
32,692 KB
testcase_09 AC 367 ms
32,952 KB
testcase_10 AC 363 ms
32,660 KB
testcase_11 AC 362 ms
32,944 KB
testcase_12 AC 370 ms
32,732 KB
testcase_13 AC 357 ms
32,880 KB
testcase_14 AC 360 ms
32,760 KB
testcase_15 AC 371 ms
32,760 KB
testcase_16 AC 362 ms
32,688 KB
testcase_17 AC 365 ms
32,956 KB
testcase_18 AC 360 ms
32,740 KB
testcase_19 AC 357 ms
32,712 KB
testcase_20 AC 365 ms
32,896 KB
testcase_21 AC 352 ms
32,956 KB
testcase_22 AC 372 ms
32,712 KB
testcase_23 AC 358 ms
32,612 KB
testcase_24 AC 107 ms
25,032 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 94 ms
25,040 KB
testcase_27 AC 104 ms
27,444 KB
testcase_28 AC 255 ms
39,140 KB
testcase_29 AC 250 ms
39,444 KB
testcase_30 AC 254 ms
38,900 KB
testcase_31 AC 250 ms
38,772 KB
testcase_32 AC 248 ms
39,356 KB
testcase_33 AC 255 ms
40,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    ll N, M, C;
    cin >> N >> M >> C;
    vector<vector<pair<ll, ll>>> g(N + 1);
    auto add_edge = [&](ll i, ll j, ll c) {
        g[i].emplace_back(j, c);
        g[j].emplace_back(i, c);
    };
    ll ans = 0;
    for(ll i = 0; i < N; i++) {
        ll A;
        cin >> A;
        add_edge(i, i + 1, A);
        ans += A;
    }
    while(M--) {
        ll L, R;
        cin >> L >> R;
        add_edge(--L, R, C);
    }
    auto dijkstra = [&](ll s) -> vector<ll> {
        vector cost(N + 1, LLONG_MAX);
        priority_queue q(greater<>{}, vector<pair<ll, ll>>{});
        auto push = [&](ll i, ll c) {
            if(cost[i] <= c) return;
            cost[i] = c;
            q.emplace(c, i);
        };
        push(s, 0);
        while(q.size()) {
            auto [c, i] = q.top();
            q.pop();
            // if(cost[i] != c) continue;
            for(auto [j, d] : g[i]) push(j, c + d);
        }
        return cost;
    };
    ans -= dijkstra(0)[N];
    cout << ans << endl;
}
0