이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <cassert>
#include <vector>
using namespace std;
using ll = long long;
const ll INF = 1.77013e15;
const int MAXN = 100;
const int MAXK = 1000;
ll buy[MAXN][MAXK];
ll sell[MAXN][MAXK];
ll d[MAXN][MAXN];
ll prof[MAXN][MAXN];
signed main() {
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < k; ++j) {
cin >> buy[i][j] >> sell[i][j];
if (buy[i][j] == -1)
buy[i][j] = INF;
if (sell[i][j] == -1)
sell[i][j] = 0;
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
d[i][j] = INF;
}
d[i][i] = 0;
}
for (int i = 0; i < m; ++i) {
int u, v, w;
cin >> u >> v >> w;
--u, --v;
d[u][v] = w;
}
for (int i = 0; i < n; ++i) {
for (int v = 0; v < n; ++v) {
for (int u = 0; u < n; ++u) {
d[v][u] = min(d[v][u], d[v][i] + d[i][u]);
}
}
}
//for (int i = 0; i < n; ++i) {
//for (int j = 0; j < n; ++j)
//cout << d[i][j] << ' ';
//cout << endl;
//}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
for (int w = 0; w < n; ++w) {
assert(d[i][j] + d[j][w] >= d[i][w]);
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
for (int t = 0; t < k; ++t) {
prof[i][j] = max(prof[i][j], sell[j][t] - buy[i][t]);
}
}
assert(prof[i][i] == 0);
}
ll ans = 0;
for (int i = 1; i < n; ++i) {
ans = max(ans, prof[0][i] / (d[0][i] + d[i][0]));
}
cout << ans << endl;
}
# | 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... |