이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |