Submission #404507

#TimeUsernameProblemLanguageResultExecution timeMemory
404507salehTravelling Merchant (APIO17_merchant)C++17
0 / 100
26 ms1448 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int MAXN = 50 + 2, INF = 1000 * 1000 * 1000 + 123, MAXK = 50 + 2; /* 4 5 2 10 9 5 2 6 4 20 15 9 7 10 9 -1 -1 16 11 1 2 1 2 3 1 1 4 1 4 3 1 3 1 1 */ int n, m, kk, d[MAXN][MAXN], b[MAXN][MAXK], s[MAXN][MAXK], dp[MAXN][MAXN][MAXN]; long double ans; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); cin >> n >> m >> kk; if (n >= MAXN || kk >= MAXK) return 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (i != j) d[i][j] = INF; for (int i = 0; i < n; i++) for (int j = 0; j < kk; j++) cin >> b[i][j] >> s[i][j]; { int v, w, t; for (int i = 0; i < m; i++) { cin >> v >> w >> t; d[--v][--w] = t; if (t != 1) return 0; } } 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]); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) for (int k = 0; k < kk; k++) if (i != j && s[j][k] > b[i][k] && d[i][j] < n && ~b[i][k]) dp[d[i][j]][i][j] = max(dp[d[i][j]][i][j], s[j][k] - b[i][k]); for (int k = 1; k < n; k++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (i != j && k >= d[i][j]) for (int o = 0; o < n; o++) if (d[i][o] + d[o][j] <= k) dp[k][i][j] = max(dp[k][i][j], dp[d[i][o]][i][o] + dp[k - d[i][o]][o][j]); for (int i = 1; i <= n; i++) for (int j = 1; j < i; j++) for (int a = 0; a < n; a++) for (int b = 0; b < n; b++) { if (d[a][b] > j || d[b][a] > i - j) continue; ans = max(ans, (long double) (dp[j][a][b] + dp[i - j][b][a]) / i); // cout << i << ' ' << a << ' ' << b << ' ' << dp[j][a][b] << ' ' << dp[i - j][b][a] << ' ' << i << endl; } cout << (int)ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...