Submission #1117459

#TimeUsernameProblemLanguageResultExecution timeMemory
1117459thtsshz_bgwrswhTravelling Merchant (APIO17_merchant)C++17
100 / 100
54 ms4188 KiB
#include <stdio.h> #include <algorithm> using namespace std; const long long INF = 1e18; long long buy[105][1005], sell[105][1005]; long long graph[105][105], profit[105][105]; long long graph2[105][105]; long long n, m, x; void floyd(long long graph[105][105]) { for (long long k = 1; k <= n; k++) for (long long i = 1; i <= n; i++) for (long long j = 1; j <= n; j++) graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]); } int main() { scanf("%lld %lld %lld", &n, &m, &x); for (long long i = 1; i <= n; i++) { for (long long j = 1; j <= n; j++) graph[i][j] = INF; for (long long j = 1; j <= x; j++) { scanf("%lld %lld", &buy[i][j], &sell[i][j]); } } for (long long i = 0; i < m; i++) { long long u, v, c; scanf("%lld %lld %lld", &u, &v, &c); graph[u][v] = c; } floyd(graph); for (long long i = 1; i <= n; i++) { for (long long j = 1; j <= n; j++) { for (long long l = 1; l <= x; l++) { if (sell[j][l] != -1 && buy[i][l] != -1) profit[i][j] = max(profit[i][j], sell[j][l] - buy[i][l]); } } } long long left = 1, right = 1e9; while (left <= right) { long long mid = (left + right) / 2; for (long long i = 1; i <= n; i++) for (long long j = 1; j <= n; j++) graph2[i][j] = mid * min(graph[i][j], INF / mid) - profit[i][j]; floyd(graph2); bool has_nonnegative_cycle = false; for (long long i = 1; i <= n; i++) if (graph2[i][i] <= 0) has_nonnegative_cycle = true; if (has_nonnegative_cycle) left = mid + 1; else right = mid - 1; } printf("%lld\n", right); }

Compilation message (stderr)

merchant.cpp: In function 'int main()':
merchant.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     scanf("%lld %lld %lld", &n, &m, &x);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:22:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |             scanf("%lld %lld", &buy[i][j], &sell[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         scanf("%lld %lld %lld", &u, &v, &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...