結果

問題 No.2321 Continuous Flip
ユーザー milanis48663220milanis48663220
提出日時 2023-05-26 22:27:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,461 bytes
コンパイル時間 1,557 ms
コンパイル使用メモリ 128,208 KB
実行使用メモリ 49,600 KB
最終ジャッジ日時 2023-08-26 12:30:45
合計ジャッジ時間 11,970 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 275 ms
43,576 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 270 ms
43,332 KB
testcase_22 WA -
testcase_23 AC 278 ms
43,316 KB
testcase_24 AC 123 ms
43,832 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 108 ms
40,560 KB
testcase_27 AC 114 ms
41,772 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 230 ms
48,972 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 229 ms
47,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

const ll INF = 1e+18;

using P = pair<ll, int>;

struct edge{
    int to;
    ll cost;
    edge(int to, ll cost): to(to), cost(cost) {}
};

vector<ll> dijkstra(int s, vector<vector<edge>> G){
    priority_queue<P, vector<P>, greater<P>> que;
    int n = G.size();
    vector<ll> d(n, INF);
    d[s] = 0;
    que.push(P(0, s));
    while(!que.empty()){
        P p = que.top();que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if(d[v] + e.cost < d[e.to]){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
    return d;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, m; ll c; cin >> n >> m >> c;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<vector<edge>> g(n+1);
    for(int i = 0; i < n; i++){
        g[i].push_back(edge(i+1, a[i]));
        g[i+1].push_back(edge(i, a[i]));
    }
    for(int i = 0; i < m; i++){
        int l, r; cin >> l >> r; l--;
        g[l].push_back(edge(r, c));
    }
    ll a_sum = accumulate(a.begin(), a.end(), 0ll);
    auto d = dijkstra(0, g);
    cout << a_sum-d[n] << endl;
}
0