Submission #741493

#TimeUsernameProblemLanguageResultExecution timeMemory
741493406Travelling Merchant (APIO17_merchant)C++17
0 / 100
89 ms1996 KiB
#include "bits/stdc++.h" #define int long long using namespace std; const long long INF = 1ll << 30; const long long INF2 = 1ll << 60; const int N = 100 + 5; const int M = 1e4 + 5; const int K = 1000 + 5; int d[N][N], n, k, m, U[M], V[M], W[M], B[N][K], S[N][K], P[N][N], e; void floyd(int d[N][N]) { for (int k = 0; k < n; k++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } signed main() { ios::sync_with_stdio(0), cin.tie(0); cin >> n >> e >> k; for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) cin >> B[i][j]; for (int j = 0; j < k; j++) cin >> S[i][j]; } for (int i = 0; i < e; i++) { cin >> U[i] >> V[i] >> W[i]; V[i]--, U[i]--; } for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) for (int l = 0; l < k; l++) if (B[i][l] != -1 && S[j][l] != -1) P[i][j] = max(P[i][j], -B[i][l] +S[j][l]); int l = 0, r = INF; while (r - l > 1) { int m = l + r >> 1; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) d[i][j] = INF2; for (int i = 0; i < e; i++) d[U[i]][V[i]] = W[i] * m; floyd(d); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) d[i][j] -= P[i][j]; floyd(d); bool ok = 0; for (int i = 0; i < n; i++) ok |= d[i][i] <= 0; if (ok) l = m; else r = m; } cout << l << '\n'; return 0; } //الان میتونی بری

Compilation message (stderr)

merchant.cpp: In function 'int main()':
merchant.cpp:35:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |   int m = 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...