結果
問題 | No.1122 Plane Tickets |
ユーザー |
![]() |
提出日時 | 2023-07-26 01:05:54 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,734 bytes |
コンパイル時間 | 1,122 ms |
コンパイル使用メモリ | 119,652 KB |
最終ジャッジ日時 | 2025-02-15 19:10:17 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 38 WA * 17 |
ソースコード
#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; }