結果

問題 No.2712 Play more!
ユーザー KKT89KKT89
提出日時 2024-03-31 14:13:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 301 ms / 2,000 ms
コード長 1,638 bytes
コンパイル時間 3,005 ms
コンパイル使用メモリ 234,252 KB
実行使用メモリ 37,088 KB
最終ジャッジ日時 2024-04-03 12:09:33
合計ジャッジ時間 5,451 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 1 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 5 ms
6,548 KB
testcase_08 AC 4 ms
6,548 KB
testcase_09 AC 5 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 60 ms
12,340 KB
testcase_12 AC 62 ms
6,548 KB
testcase_13 AC 80 ms
20,520 KB
testcase_14 AC 168 ms
6,548 KB
testcase_15 AC 253 ms
37,088 KB
testcase_16 AC 13 ms
8,172 KB
testcase_17 AC 15 ms
8,260 KB
testcase_18 AC 40 ms
8,264 KB
testcase_19 AC 5 ms
6,548 KB
testcase_20 AC 33 ms
8,340 KB
testcase_21 AC 15 ms
8,364 KB
testcase_22 AC 301 ms
20,768 KB
testcase_23 AC 10 ms
6,548 KB
testcase_24 AC 37 ms
12,304 KB
testcase_25 AC 21 ms
12,296 KB
testcase_26 AC 17 ms
6,548 KB
testcase_27 AC 35 ms
6,548 KB
testcase_28 AC 3 ms
6,548 KB
testcase_29 AC 39 ms
12,304 KB
testcase_30 AC 230 ms
12,452 KB
testcase_31 AC 5 ms
6,548 KB
testcase_32 AC 4 ms
6,548 KB
testcase_33 AC 2 ms
6,548 KB
testcase_34 AC 2 ms
6,548 KB
testcase_35 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m; cin >> n >> m;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<vector<pair<int,ll>>> g(n);
    vector<vector<int>> rg(n);
    for (int i = 0; i < m; ++i) {
        int x,y,z; cin >> x >> y >> z;
        x -= 1, y -= 1;
        g[x].push_back({y, z});
        rg[y].push_back(x);
    }
    vector<bool> ok(n);
    queue<int> q; q.push(n-1); ok[n-1] = true;
    while (q.size()) {
        int s = q.front(); q.pop();
        for (int t : rg[s]) {
            if (!ok[t]) {
                ok[t] = true;
                q.push(t);
            }
        }
    }
    vector<ll> dp(n, -1e18);
    dp[0] = a[0];
    priority_queue<pair<ll,int>> pq;
    pq.push({dp[0], 0});
    vector<int> cnt(n);
    while (pq.size()) {
        auto p = pq.top(); pq.pop();
        ll score = p.first, j = p.second;
        if (dp[j] != score) continue;
        cnt[j] += 1;
        if (cnt[j] >= 10*n) {
            cout << "inf" << endl;
            return 0;
        }
        for (auto to : g[j]) {
            ll nxt = score - to.second + a[to.first];
            int t = to.first;
            if (!ok[t]) continue;
            if (dp[t] < nxt) {
                dp[t] = nxt;
                pq.push({nxt, t});
            }
        }
    }
    cout << dp.back() << endl;
}
0