結果

問題 No.2321 Continuous Flip
ユーザー ぷらぷら
提出日時 2023-07-26 03:54:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 1,438 bytes
コンパイル時間 2,418 ms
コンパイル使用メモリ 204,888 KB
実行使用メモリ 21,728 KB
最終ジャッジ日時 2024-04-10 17:57:47
合計ジャッジ時間 9,954 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 159 ms
18,088 KB
testcase_05 AC 152 ms
18,080 KB
testcase_06 AC 151 ms
17,960 KB
testcase_07 AC 157 ms
17,956 KB
testcase_08 AC 162 ms
17,960 KB
testcase_09 AC 155 ms
17,948 KB
testcase_10 AC 154 ms
18,208 KB
testcase_11 AC 156 ms
17,952 KB
testcase_12 AC 153 ms
17,956 KB
testcase_13 AC 154 ms
18,060 KB
testcase_14 AC 151 ms
17,840 KB
testcase_15 AC 161 ms
18,016 KB
testcase_16 AC 157 ms
18,080 KB
testcase_17 AC 162 ms
18,084 KB
testcase_18 AC 160 ms
18,208 KB
testcase_19 AC 162 ms
18,084 KB
testcase_20 AC 165 ms
18,084 KB
testcase_21 AC 158 ms
18,080 KB
testcase_22 AC 157 ms
17,960 KB
testcase_23 AC 159 ms
18,076 KB
testcase_24 AC 82 ms
16,512 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 61 ms
12,068 KB
testcase_27 AC 64 ms
12,728 KB
testcase_28 AC 138 ms
21,728 KB
testcase_29 AC 137 ms
21,472 KB
testcase_30 AC 139 ms
21,724 KB
testcase_31 AC 138 ms
21,728 KB
testcase_32 AC 140 ms
21,600 KB
testcase_33 AC 143 ms
21,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

long long inf = 1001001001001001001;

bool chmin(long long &x,long long y) {
    if(x > y) {
        x = y;
        return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M,C;
    cin >> N >> M >> C;
    vector<int>A(N);
    long long sum = 0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        sum += A[i];
    }
    vector<vector<int>>road(N+1);
    for(int i = 0; i < M; i++) {
        int L,R;
        cin >> L >> R;
        L--;
        road[L].push_back(R);
        road[R].push_back(L);
    }
    vector<long long>dist(N+1,inf);
    dist[0] = 0;
    priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>>que;
    que.push({0,0});
    while(!que.empty()) {
        auto a = que.top();
        que.pop();
        if(dist[a.second] != a.first) continue;
        for(auto i:road[a.second]) {
            if(chmin(dist[i],a.first+C)) {
                que.push({dist[i],i});
            }
        }
        if(a.second < N) {
            if(chmin(dist[a.second+1],a.first+A[a.second])) {
                que.push({dist[a.second+1],a.second+1});
            }
        }
        if(a.second) {
            if(chmin(dist[a.second-1],a.first+A[a.second-1])) {
                que.push({dist[a.second-1],a.second-1});
            }
        }
    }
    cout << sum-dist[N] << "\n";
}
0