Submission #950182

#TimeUsernameProblemLanguageResultExecution timeMemory
950182abczzTravelling Merchant (APIO17_merchant)C++14
100 / 100
121 ms4248 KiB
#include <iostream> #include <vector> #include <algorithm> #include <array> #include <deque> #include <queue> #define ll long long using namespace std; ll dist[100][100], C[100][100], X[100][100], l, r, mid; ll n, m, k, a, b, c, cur, A[100][1000], B[100][1000]; int main() { cin >> n >> m >> k; for (int i=0; i<n; ++i) { for (int j=0; j<n; ++j) { dist[i][j] = 1e18; } } for (int i=0; i<n; ++i) { dist[i][i] = 0; for (int j=0; j<k; ++j) { cin >> A[i][j] >> B[i][j]; } } for (int i=0; i<m; ++i) { cin >> a >> b >> c; --a, --b; dist[a][b] = min(dist[a][b], c); } for (int x=0; x<n; ++x) { for (int i=0; i<n; ++i) { for (int j=0; j<n; ++j) { dist[i][j] = min(dist[i][x] + dist[x][j], dist[i][j]); } } } for (int i=0; i<n; ++i) { for (int j=0; j<n; ++j) { if (i != j) { for (int x=0; x<k; ++x) { if (min(A[i][x], B[j][x]) != -1) C[i][j] = max(C[i][j], B[j][x]-A[i][x]); } } } } l = 0, r = 1e9; while (l < r) { mid = (l+r+1)/2; for (int i=0; i<n; ++i) { for (int j=0; j<n; ++j) { if (dist[i][j] != 1e18) X[i][j] = C[i][j] - mid * dist[i][j]; else X[i][j] = -1e18; } } for (int x=0; x<n; ++x) { for (int i=0; i<n; ++i) { for (int j=0; j<n; ++j) { X[i][j] = max(X[i][j], min((ll)1e18, X[i][x] + X[x][j])); X[i][j] = max(X[i][j], (ll)-1e18); } } } cur = -1e18; for (int i=0; i<n; ++i) { for (int j=0; j<n; ++j) { if (i != j) { cur = max(cur, X[i][j]+X[j][i]); } } } if (cur >= 0) l = mid; else r = mid-1; } cout << l << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...