結果

問題 No.1898 Battle and Exchange
ユーザー 👑 NachiaNachia
提出日時 2022-04-08 22:19:32
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 431 ms / 5,000 ms
コード長 2,545 bytes
コンパイル時間 1,066 ms
コンパイル使用メモリ 93,976 KB
実行使用メモリ 14,700 KB
最終ジャッジ日時 2023-08-19 00:49:47
合計ジャッジ時間 20,510 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 14 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 13 ms
4,380 KB
testcase_18 AC 74 ms
4,812 KB
testcase_19 AC 117 ms
5,860 KB
testcase_20 AC 114 ms
6,416 KB
testcase_21 AC 314 ms
11,192 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 8 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 42 ms
5,916 KB
testcase_33 AC 94 ms
8,076 KB
testcase_34 AC 41 ms
5,516 KB
testcase_35 AC 70 ms
6,740 KB
testcase_36 AC 49 ms
6,360 KB
testcase_37 AC 41 ms
4,432 KB
testcase_38 AC 431 ms
14,700 KB
testcase_39 AC 259 ms
12,656 KB
testcase_40 AC 426 ms
13,896 KB
testcase_41 AC 220 ms
12,208 KB
testcase_42 AC 10 ms
4,380 KB
testcase_43 AC 201 ms
9,148 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 20 ms
4,376 KB
testcase_46 AC 95 ms
5,912 KB
testcase_47 AC 16 ms
4,380 KB
testcase_48 AC 36 ms
4,380 KB
testcase_49 AC 4 ms
4,380 KB
testcase_50 AC 4 ms
4,376 KB
testcase_51 AC 4 ms
4,376 KB
testcase_52 AC 5 ms
4,376 KB
testcase_53 AC 44 ms
4,688 KB
testcase_54 AC 29 ms
4,844 KB
testcase_55 AC 65 ms
4,820 KB
testcase_56 AC 41 ms
5,020 KB
testcase_57 AC 408 ms
11,644 KB
testcase_58 AC 268 ms
11,712 KB
testcase_59 AC 383 ms
11,880 KB
testcase_60 AC 308 ms
11,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <queue>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int N,M;
vector<vector<int>> E;
vector<array<i64, 3>> A;

i64 sum(array<i64, 3> a){
    i64 ans = 0;
    for(auto aa : a) ans += aa;
    return ans;
}
bool battle(array<i64, 3>& a, array<i64, 3> b){
    if(sum(a) <= sum(b)) return false;
    if(a[0] < b[2]) swap(a[0], b[2]);
    return true;
}
bool battle2(array<i64, 3>& a, array<i64, 3> b){
    if(sum(a) <= sum(b)) return false;
    array<i64, 6> buf;
    rep(t,3) buf[t] = a[t];
    rep(t,3) buf[3+t] = b[t];
    sort(buf.begin(), buf.end());
    rep(t,3) a[t] = buf[3+t];
    return true;
}

bool solve(array<i64, 3> P){
    auto p = P;
    if(!battle(p, A[0])) return false;
    bool ok = false;
    for(auto e : E[0]) if(battle(p, A[e])) ok = true;
    if(!ok) return false;
    p = P;
    vector<int> pushed(N, 0);
    vector<int> vis(N, 0);
    priority_queue<pair<i64, int>> Q;
    Q.push(make_pair(-sum(A[0]), 0));
    pushed[0] = 1;
    //cout << " P = [ " << P[0] << ", " << P[1] << ", " << P[2] << " ]" << endl;
    while(Q.size()){
        int v = Q.top().second;
        Q.pop();
        if(!battle2(p, A[v])) break;
        //cout << "    v = " << v << ", p = [ " << p[0] << ", " << p[1] << ", " << p[2] << " ]" << endl;
        vis[v] = 1;
        for(int e : E[v]) if(!pushed[e]){
            Q.push(make_pair(-sum(A[e]), e));
            pushed[e] = 1;
        }
    }
    return vis[N-1];
}

int main(){
    cin >> N >> M;
    E.resize(N);
    rep(i,M){
        int u,v; cin >> u >> v; u--; v--;
        E[u].push_back(v);
        E[v].push_back(u);
    }
    A.resize(N);
    rep(i,N) rep(t,3){ cin >> A[i][t]; A[i][t]--; }
    rep(i,N) sort(A[i].begin(), A[i].end());

    array<i64,3> ans;
    rep(t,3) ans[t] = 1<<30;

    {
        i64 ng = 0, ok = 1<<30;
        while(ng + 1 < ok){
            i64 m = (ng+ok) / 2;
            array<i64, 3> init = {};
            init[2] = m;
            if(solve(init)) ok = m; else ng = m;
        }
        array<i64, 3> tmp = {};
        tmp[2] = ok;
        if(sum(ans) > sum(tmp)) ans = tmp;
    }

    rep(t,3){
        if(t) cout << ' ';
        cout << (ans[t] + 1);
    }
    cout << '\n';
    return 0;
}

struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;
0