제출 #404219

#제출 시각아이디문제언어결과실행 시간메모리
404219wiwiho여행하는 상인 (APIO17_merchant)C++14
100 / 100
112 ms4216 KiB
#include <bits/stdc++.h> #include <bits/extc++.h> #define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define iter(a) a.begin(), a.end() #define riter(a) a.rbegin(), a.rend() #define lsort(a) sort(iter(a)) #define gsort(a) sort(riter(a)) #define pb(a) push_back(a) #define eb(a) emplace_back(a) #define pf(a) push_front(a) #define ef(a) emplace_front(a) #define pob pop_back() #define pof pop_front() #define mp(a, b) make_pair(a, b) #define F first #define S second #define mt make_tuple #define gt(t, i) get<i>(t) #define tomax(a, b) ((a) = max((a), (b))) #define tomin(a, b) ((a) = min((a), (b))) #define topos(a) ((a) = (((a) % MOD + MOD) % MOD)) #define uni(a) a.resize(unique(iter(a)) - a.begin()) #define printv(a, b) {bool pvaspace=false; \ for(auto pva : a){ \ if(pvaspace) b << " "; pvaspace=true;\ b << pva;\ }\ b << "\n";} using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef unsigned long long ull; typedef long double ld; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; using tiii = tuple<int, int, int>; const ll MOD = 1000000007; const ll MAX = 2147483647; template<typename A, typename B> ostream& operator<<(ostream& o, pair<A, B> p){ return o << '(' << p.F << ',' << p.S << ')'; } ll ifloor(ll a, ll b){ if(b < 0) a *= -1, b *= -1; if(a < 0) return (a - b + 1) / b; else return a / b; } ll iceil(ll a, ll b){ if(b < 0) a *= -1, b *= -1; if(a > 0) return (a + b - 1) / b; else return a / b; } int n, m, K; vector<vector<ll>> gv, gt; bool check(ll x){ vector<vector<ll>> dis(n + 1, vector<ll>(n + 1, 1LL << 60)); for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ if(gt[i][j] != -1) dis[i][j] = -gv[i][j] + gt[i][j] * x; } } for(int k = 1; k <= n; k++){ for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]); } } } // cerr << "test " << x << "\n"; // for(int i =1 ; i <= n; i++) printv(dis[i], cerr); ll ans = 1LL << 60; for(int i = 1; i <= n; i++) ans = min(ans, dis[i][i]); return ans <= 0; } int main(){ StarBurstStream cin >> n >> m >> K; vector<vector<ll>> buy(n + 1, vector<ll>(K + 1)); vector<vector<ll>> sell(n + 1, vector<ll>(K + 1)); gv.resize(n + 1, vector<ll>(n + 1)); gt.resize(n + 1, vector<ll>(n + 1, MAX)); for(int i = 1; i <= n; i++){ for(int j = 1; j <= K; j++){ cin >> buy[i][j] >> sell[i][j]; } } for(int i = 0; i < m; i++){ int u, v, w; cin >> u >> v >> w; gt[u][v] = w; } for(int k = 1; k <= n; k++){ for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ gt[i][j] = min(gt[i][j], gt[i][k] + gt[k][j]); } } } for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ if(gt[i][j] == MAX) continue; for(int k = 1; k <= K; k++){ if(buy[i][k] == -1 || sell[j][k] == -1) continue; gv[i][j] = max(gv[i][j], sell[j][k] - buy[i][k]); } } } // for(int i = 1; i <= n; i++) printv(gv[i], cerr); ll l = 0, r = 1000000000; while(l < r){ ll mid = (l + r + 1) / 2; if(check(mid)) l = mid; else r = mid - 1; } cout << l << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...