Submission #555784

#TimeUsernameProblemLanguageResultExecution timeMemory
555784cadmiumskyTravelling Merchant (APIO17_merchant)C++14
0 / 100
112 ms712 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int ll const ll inf = 5e14 + 5; const int nmax = 105; void fw(int n, ll dist[nmax][nmax]) { for(int h = 0; h < n; h++) { for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) dist[i][j] = min(dist[i][j], dist[i][h] + dist[h][j]); } } } void print(int n, ll dist[nmax][nmax]) { //for(int i = 0; i < n; i++) { //for(int j = 0; j < n; j++) //cerr << dist[i][j] << ' '; //cerr << '\n'; //} return; } ll dist[nmax][nmax], cost[nmax][nmax], alter[nmax][nmax]; ll buy[nmax][nmax], sell[nmax][nmax]; bool check(int n, int coef) { //cerr << "Alter with coef " << coef << '\n'; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) alter[i][j] = -(cost[i][j] - dist[i][j] * coef); } print(n, alter); fw(n, alter); for(int i = 0; i < n; i++) { if(alter[i][i] <= 0) return 1; } return 0; } signed main() { int n, m, k; cin >> n >> m >> k; for(int i = 0; i < n; i++) { for(int j = 0; j < k; j++) { cin >> buy[i][j] >> sell[i][j]; if(buy[i][j] == -1) buy[i][j] = inf; if(sell[i][j] == -1) sell[i][j] = -inf; } } for(int i = 0; i< n; i++) for(int j = 0; j < n; j++) dist[i][j] = inf; for(int i = 0, x, y, c; i < m; i++) cin >> x >> y >> c, --x, --y, dist[x][y] = min(dist[x][y], c); fw(n, dist); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { cost[i][j] = 0; for(int h = 0; h < k; h++) cost[i][j] = max(cost[i][j], sell[j][h] - buy[i][h]); } } //cerr << "Cost:\n"; print(n, cost); //cerr << "Dist:\n"; print(n, dist); int l = 0, r = 1e9 + 5, mid; while(r - l > 1) { mid = l + r >> 1; if(check(n, mid)) l = mid; else r = mid; } cout << l << '\n'; }

Compilation message (stderr)

merchant.cpp: In function 'int main()':
merchant.cpp:75:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   75 |     mid = l + r >> 1;
      |           ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...