Submission #260994

#TimeUsernameProblemLanguageResultExecution timeMemory
260994evpipisTravelling Merchant (APIO17_merchant)C++11
33 / 100
367 ms1656 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int len = 205, max_k = 1005, inf = 1e9+10; const ll long_inf = 1e18+10; int n, m, k; int dis[len][len], prof[len][len], buy[len][max_k], sell[len][max_k]; ll path[len][len]; bool check(int c){ // initialize path for (int i = 0; i < 2*n; i++) for (int j = 0; j < 2*n; j++) path[i][j] = long_inf; // here it is more than 1e18 for (int i = 0; i < 2*n; i++) path[i][i] = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (dis[i][j] != inf) path[2*i][2*j+1] = c*1LL*dis[i][j] - prof[i][j]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (dis[i][j] != inf) path[2*i+1][2*j] = c*1LL*dis[i][j]; // compute path for (int d = 0; d < 2*n; d++) for (int i = 0; i < 2*n; i++) for (int j = 0; j < 2*n; j++) path[i][j] = min(path[i][j], path[i][d]+path[d][j]); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (i != j && path[2*i][2*j+1]+path[2*j+1][2*i] <= 0) return true; return false; } int bs(){ int l = 1, r = 1e9, ans = 0; while (l <= r){ int mid = (l+r)/2; if (check(mid)) ans = mid, l = mid+1; else r = mid-1; } return ans; } int main(){ scanf("%d %d %d", &n, &m, &k); for (int i = 0; i < n; i++) for (int j = 0; j < k; j++) scanf("%d %d", &buy[i][j], &sell[i][j]); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) dis[i][j] = inf; // here inf = 1e9+(something) for (int i = 0; i < n; i++) dis[i][i] = 0; for (int i = 0; i < m; i++){ int a, b, c; scanf("%d %d %d", &a, &b, &c); dis[a-1][b-1] = c; } // fix dis, prof... for (int d = 0; d < n; d++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) dis[i][j] = min(dis[i][j], dis[i][d]+dis[d][j]); for (int a = 0; a < n; a++) for (int b = 0; b < n; b++) for (int d = 0; d < k; d++) if (buy[a][d] != -1 && sell[b][d] != -1) prof[a][b] = max(prof[a][b], sell[b][d]-buy[a][d]); printf("%d\n", bs()); return 0; }

Compilation message (stderr)

merchant.cpp: In function 'int main()':
merchant.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &n, &m, &k);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:60:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d", &buy[i][j], &sell[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &a, &b, &c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...