Submission #136534

#TimeUsernameProblemLanguageResultExecution timeMemory
136534MilkiTravelling Merchant (APIO17_merchant)C++14
100 / 100
106 ms4280 KiB
#include<bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = a; i < b; ++i) #define REP(i, n) FOR(i, 0, n) #define _ << " " << #define sz(x) ((int) x.size()) #define pb(x) push_back(x) #define TRACE(x) cerr << #x << " = " << x << endl typedef long long ll; typedef pair<int, int> point; const int MAXN = 105, MAXK = 1e3 + 5; const ll inf = 1e9; ll n, m, items; ll dist[MAXN][MAXN]; ll buy[MAXN][MAXK], sell[MAXN][MAXK], profit[MAXN][MAXN]; bool check(ll x){ ll d[MAXN][MAXN]; REP(i, n) REP(j, n) d[i][j] = -1e13; REP(i, n) REP(j, n) d[i][j] = max(d[i][j], profit[i][j] - dist[i][j] * x); REP(k, n) REP(i, n) REP(j, n) d[i][j] = max(d[i][j], d[i][k] + d[k][j]); REP(i, n) if(d[i][i] >= 0) return true; return false; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); REP(i, MAXN) REP(j, MAXN) dist[i][j] = inf; cin >> n >> m >> items; REP(i, n) REP(j, items){ cin >> buy[i][j] >> sell[i][j]; } REP(i, m){ ll a, b, c; cin >> a >> b >> c; a --; b --; dist[a][b] = min(dist[a][b], c); } REP(k, n) REP(i, n) REP(j, n) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); REP(i, n) REP(j, n) REP(k, items) if(buy[i][k] != -1 && sell[j][k] != -1) profit[i][j] = max(profit[i][j], sell[j][k] - buy[i][k]); ll lo = 0, hi = 1e9; while(lo < hi){ ll mid = (lo + hi + 1) >> 1; if(check(mid)) lo = mid; else hi = mid - 1; } cout << lo; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...