結果

問題 No.1122 Plane Tickets
ユーザー milanis48663220milanis48663220
提出日時 2023-07-26 01:05:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,734 bytes
コンパイル時間 1,008 ms
コンパイル使用メモリ 122,616 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-10 15:31:08
合計ジャッジ時間 2,568 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 WA -
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 WA -
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 WA -
testcase_29 AC 1 ms
6,940 KB
testcase_30 AC 2 ms
6,940 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 1 ms
6,944 KB
testcase_36 AC 1 ms
6,944 KB
testcase_37 WA -
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 2 ms
6,940 KB
testcase_42 AC 2 ms
6,940 KB
testcase_43 WA -
testcase_44 AC 2 ms
6,940 KB
testcase_45 AC 2 ms
6,940 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 1 ms
6,944 KB
testcase_48 AC 1 ms
6,944 KB
testcase_49 WA -
testcase_50 AC 2 ms
6,940 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
権限があれば一括ダウンロードができます

ソースコード

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;

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

//return
//true:if nagetive loop does not exist
//false:if negative loop exists
//d:result
bool bellmanford(vector<edge> es, vector<ll> &d, int s){
    int n = d.size();
    for(int i = 0; i < n; i++){
        d[i] = inf;
    }
    d[s] = 0;
    int cnt_loop = 0;
    while(true){
        cnt_loop++;
        bool update = false;
        for(int i = 0; i < es.size(); i++){
            edge e = es[i];
            if(d[e.from] != inf && d[e.from]+e.cost < d[e.to]){
                d[e.to] = d[e.from]+e.cost;
                update = true;
            }
        }
        if(!update) {
            return true;
        }
        else if(cnt_loop >= n) {
            return false;
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll a, b, c, d, e; cin >> a >> b >> c >> d >> e;
    auto judge = [&](ll x){
        vector<edge> es;
        for(int i = 0; i < 5; i++) es.push_back(edge(i+1, i, 0));
        es.push_back(edge(3, 1, a-x));
        es.push_back(edge(4, 2, b-x));
        es.push_back(edge(0, 3, c));
        es.push_back(edge(1, 4, d));
        es.push_back(edge(2, 5, e));
        vector<ll> d(6);
        return bellmanford(es, d, 0);
    };
    ll l = 0, r = 1e16;
    while(r-l > 1){
        ll x = (l+r)/2;
        if(judge(x)) {
            l = x;
        }else{
            r = x;
        }
    }
    cout << l << endl;
}
0