結果
| 問題 |
No.1122 Plane Tickets
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2023-07-26 01:12:21 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 24 ms / 1,000 ms |
| コード長 | 2,791 bytes |
| コンパイル時間 | 1,081 ms |
| コンパイル使用メモリ | 119,132 KB |
| 最終ジャッジ日時 | 2025-02-15 19:10:23 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 55 |
ソースコード
#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);
bool f = bellmanford(es, d, 0);
if(!f) return false;
return d[5] >= x;
};
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;
}
milanis48663220