結果

問題 No.1898 Battle and Exchange
ユーザー 👑 colognecologne
提出日時 2022-04-08 21:52:51
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 422 ms / 5,000 ms
コード長 2,030 bytes
コンパイル時間 4,357 ms
コンパイル使用メモリ 268,152 KB
実行使用メモリ 11,452 KB
最終ジャッジ日時 2023-08-19 00:31:00
合計ジャッジ時間 20,291 ms
ジャッジサーバーID
(参考情報)
judge9 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 11 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 11 ms
4,376 KB
testcase_18 AC 50 ms
4,760 KB
testcase_19 AC 93 ms
5,152 KB
testcase_20 AC 63 ms
5,540 KB
testcase_21 AC 191 ms
9,116 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 8 ms
4,376 KB
testcase_28 AC 23 ms
4,380 KB
testcase_29 AC 40 ms
4,384 KB
testcase_30 AC 11 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 95 ms
5,240 KB
testcase_33 AC 177 ms
6,748 KB
testcase_34 AC 74 ms
5,044 KB
testcase_35 AC 114 ms
6,008 KB
testcase_36 AC 110 ms
5,764 KB
testcase_37 AC 35 ms
4,376 KB
testcase_38 AC 422 ms
11,452 KB
testcase_39 AC 136 ms
9,800 KB
testcase_40 AC 389 ms
10,460 KB
testcase_41 AC 114 ms
9,504 KB
testcase_42 AC 13 ms
4,376 KB
testcase_43 AC 125 ms
7,984 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 27 ms
4,376 KB
testcase_46 AC 106 ms
5,340 KB
testcase_47 AC 25 ms
4,380 KB
testcase_48 AC 18 ms
4,376 KB
testcase_49 AC 17 ms
4,376 KB
testcase_50 AC 12 ms
4,376 KB
testcase_51 AC 14 ms
4,376 KB
testcase_52 AC 30 ms
4,380 KB
testcase_53 AC 36 ms
4,756 KB
testcase_54 AC 301 ms
5,364 KB
testcase_55 AC 227 ms
5,224 KB
testcase_56 AC 48 ms
5,116 KB
testcase_57 AC 403 ms
9,704 KB
testcase_58 AC 298 ms
9,704 KB
testcase_59 AC 286 ms
9,720 KB
testcase_60 AC 291 ms
9,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> V(N);
    for (int i = 0; i < M; i++)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        V[u - 1].push_back(v - 1);
        V[v - 1].push_back(u - 1);
    }
    vector<tuple<int, int, int>> ABC(N);
    for (auto &[a, b, c] : ABC)
        cin >> a >> b >> c;

    auto can = [&](int x)
    {
        // at least, can you go out?
        {
            auto [a, b, c] = ABC[0];
            if (a + b + c >= x + 2)
                return false;

            int nx = x + max({a, b, c}) + 1;
            int minv = 1e9;
            for (auto u : V[0])
            {
                auto [a, b, c] = ABC[u];
                minv = min(minv, a + b + c);
            }
            if (minv >= nx)
                return false;
        }

        tuple<int, int, int> cur = {x, 1, 1};

        using pii = pair<int, int>;
        priority_queue<pii, vector<pii>, greater<pii>> Q;
        vector<bool> vis(N, 0);
        auto [a, b, c] = ABC[0];
        Q.emplace(a + b + c, 0);
        while (!Q.empty())
        {
            auto [w, u] = Q.top();
            Q.pop();
            if (vis[u])
                continue;
            vis[u] = true;
            auto [ca, cb, cc] = cur;
            if (w >= ca + cb + cc)
                return false;
            if (u == N - 1)
                return true;
            auto [xx, yy, zz] = ABC[u];
            int cs[6] = {ca, cb, cc, xx, yy, zz};
            sort(cs, cs + 6);
            cur = {cs[5], cs[4], cs[3]};
            for (auto x : V[u])
            {
                auto [a, b, c] = ABC[x];
                Q.emplace(a + b + c, x);
            }
        }
        return false;
    };

    int ng = 0;
    int ok = 300'000'000;
    while (ng + 1 != ok)
    {
        int mi = (ng + ok) / 2;
        if (can(mi))
            ok = mi;
        else
            ng = mi;
    }
    cout << ok << " " << 1 << " " << 1 << endl;
}
0