結果

問題 No.2712 Play more!
ユーザー yasunoriyasunori
提出日時 2024-03-31 14:40:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 3,274 bytes
コンパイル時間 2,570 ms
コンパイル使用メモリ 222,916 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-03 12:10:00
合計ジャッジ時間 5,107 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 4 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 74 ms
6,676 KB
testcase_08 AC 69 ms
6,676 KB
testcase_09 AC 70 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 18 ms
6,676 KB
testcase_12 AC 143 ms
6,676 KB
testcase_13 AC 29 ms
6,676 KB
testcase_14 AC 114 ms
6,676 KB
testcase_15 AC 172 ms
6,676 KB
testcase_16 AC 10 ms
6,676 KB
testcase_17 AC 5 ms
6,676 KB
testcase_18 AC 11 ms
6,676 KB
testcase_19 AC 6 ms
6,676 KB
testcase_20 AC 49 ms
6,676 KB
testcase_21 AC 17 ms
6,676 KB
testcase_22 AC 76 ms
6,676 KB
testcase_23 AC 9 ms
6,676 KB
testcase_24 AC 12 ms
6,676 KB
testcase_25 AC 6 ms
6,676 KB
testcase_26 AC 15 ms
6,676 KB
testcase_27 AC 98 ms
6,676 KB
testcase_28 AC 79 ms
6,676 KB
testcase_29 AC 17 ms
6,676 KB
testcase_30 AC 220 ms
6,676 KB
testcase_31 AC 70 ms
6,676 KB
testcase_32 AC 66 ms
6,676 KB
testcase_33 AC 3 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template <typename T> using min_priority_queue = priority_queue<T,vector<T>,greater<T>>;

template<typename T>
void printv(vector<T> &v){
    bool b = false;
    for(auto i : v){
        if(b) cout << " ";
        else b = true;
        cout << i;
    }
    cout << endl;
}

template <typename T>
bool chmin(T &a, const T& b) {
    if (a > b) {
        a = b;  // aをbで更新
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T &a, const T& b) {
    if (a < b) {
        a = b;  // aをbで更新
        return true;
    }
    return false;
}

void yn(bool b){
    if(b) cout << "Yes" << endl;
    else cout << "No" << endl;
}

bool debug;
bool randomInput;
bool debugOutput;
int numOfTestCase;

using ans_type = int;

void input(){
    if(numOfTestCase > 1){
        ;
    }

    if(randomInput){
        
    }
    else{
        
    }
    return;
}

void output_input(){
    ;
}

ans_type calc(){
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    for(auto &a : A) cin >> a;
    vector<tuple<int,int,int>> V(M);
    for(auto &[a, b, c] : V){
        cin >> a >> b >> c;
        a--; b--;
    }

    vector<vector<pair<int64_t, int>>> G(2*N);
    vector<vector<pair<int64_t, int>>> Ginv(2*N);
    for(auto[a, b, c] : V){
        G[2*a+1].push_back({c, 2*b});
        Ginv[2*b].push_back({c, 2*a+1});
    }
    for(int i = 0; i < N; i++){
        G[2*i].push_back({-A[i], 2*i+1});
        Ginv[2*i+1].push_back({-A[i], 2*i});
    }

    int64_t INF = 1001002003004005006;

    vector<int64_t> D(2*N, INF);
    D[0] = 0;

    for(int i = 0; i < 2*N-1; i++){
        for(int j = 0; j < 2*N-1; j++){
            for(auto[d, k] : G[j]){
                chmin(D[k], D[j]+d);
            }
        }
    }

    vector<int> W;
    for(int j = 0; j < 2*N-1; j++){
        for(auto[d, k] : G[j]){
            if(D[k] > D[j]+d){
                W.push_back(k);
            }
        }
    }

    vector<bool> check(2*N, false);
    queue<int> q;
    check[2*N-1] = true;
    q.push(2*N-1);
    while(q.size()){
        int pos = q.front();
        q.pop();
        for(auto [e, j] : Ginv[pos]){
            if(check[j]) continue;
            check[j] = true;
            q.push(j);
        }
    }

    for(int i : W){
        if(check[i]){
            cout << "inf" << endl;
            return 0;
        }
    }
    cout << -D[2*N-1] << endl;

    //for(auto i : D) cout << i << " ";cout << endl;

    return ans_type();
}

ans_type calc_simple(){
    return ans_type();
}

void output(ans_type ans){
    return;
}

int main(){
    debug = 0;
    randomInput = 0;
    debugOutput = 0;
    numOfTestCase = 1;
    srand(time(NULL));
    cout << fixed << setprecision(12);
    
    if(numOfTestCase == 0) cin >> numOfTestCase;

    if(debug){
        for(int i = 0; i < numOfTestCase; i++){
            input();
            ans_type ans = calc();
            ans_type ansSimple = calc_simple();
            if(ans != ansSimple){
                output_input();
                output(ans);
                output(ansSimple);
            }
        }
    }
    else{
        for(int i = 0; i < numOfTestCase; i++){
            input();
            output(calc());
        }
    }

    return 0;
}
0