Submission #603151

#TimeUsernameProblemLanguageResultExecution timeMemory
603151AA_SurelyTravelling Merchant (APIO17_merchant)C++14
100 / 100
133 ms4188 KiB
#include <bits/stdc++.h> #define FOR(i, x, n) for(int i = x; i < n; i++) #define F0R(i, n) FOR(i, 0, n) #define ROF(i, x, n) for(int i = n - 1; i >= x; i--) #define R0F(i, n) ROF(i, 0, n) #define WTF cout << "WTF" << endl #define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define F first #define PB push_back #define ALL(x) x.begin(), x.end() #define RALL(x) x.rbegin(), x.rend() using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef pair<int, PII> PPI; typedef vector<int> VI; typedef vector<LL> VLL; typedef vector<PII> VPII; typedef vector<PLL> VPLL; const int N = 100 + 7; const int K = 1000 + 7; const LL INF = 1e18; #define B 0 #define S 1 LL n, m, k; LL dist[N][N], obj[N][K][2], opt[N][N], adj[N][N]; void init() { cin >> n >> m >> k; F0R(i, n) F0R(j, k) cin >> obj[i][j][B] >> obj[i][j][S]; F0R(i, n) F0R(j, n) dist[i][j] = INF; F0R(i, n) dist[i][i] = 0; F0R(i, m) { int u, v, w; cin >> u >> v >> w; u--; v--; dist[u][v] = w; } return; } void precalc() { F0R(x, n) F0R(i, n) F0R(j, n) dist[i][j] = min(dist[i][j], dist[i][x] + dist[x][j]); F0R(i, n) F0R(j, n) F0R(x, k) if (obj[i][x][B] != -1 && obj[j][x][S] != -1) opt[i][j] = max(opt[i][j], - obj[i][x][B] + obj[j][x][S]); return; } bool check(LL m) { F0R(i, n) F0R(j, n) adj[i][j] = -INF; F0R(i, n) F0R(j, n) if (dist[i][j] != INF && i != j) adj[i][j] = opt[i][j] - m * dist[i][j]; F0R(go, n) F0R(i, n) F0R(j, n) if (adj[i][j] != INF) adj[i][j] = max(adj[i][j], min(INF, adj[i][go] + adj[go][j])); F0R(i, n) if (adj[i][i] >= 0) return 1; return 0; } int main() { IOS; init(); precalc(); //cout << check(2) << endl; //F0R(i, 10) cout << check(i) << ' '; cout << endl; return 0; LL l = 0, r = 1e9, mid; while(l < r) { mid = (l + r) >> 1; if (check(mid)) l = mid + 1; else r = mid; } cout << l - 1 << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...