이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 101;
const int K = 1001;
const int INF = 1e18;
int n, m, k;
int dist[N][N], p[N][N], buy[N][K], sell[N][K];
bool check(int k) {
vector<vector<int>> d(N, vector<int> (N, INF));
for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) {
if (j != i && dist[i][j] != INF) {
d[i][j] = k * min(dist[i][j], INF / k) - p[i][j];
}
}
for (int x = 1; x <= n; x++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) {
if (d[i][x] < INF && d[x][j] < INF) d[i][j] = min(d[i][j], max(-INF, d[i][x] + d[x][j]));
}
for (int x = 1; x <= n; x++) if (d[x][x] <= 0) return true;
return false;
}
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) for (int j = 1; j <= k; j++) cin >> buy[i][j] >> sell[i][j];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == j) continue;
for (int id = 1; id <= k; id++) {
if (sell[j][id] == -1 || buy[i][id] == -1) continue;
p[i][j] = max(p[i][j], sell[j][id] - buy[i][id]);
}
}
}
for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (i != j) dist[i][j] = INF;
for (int i = 1; i <= m; i++) {
int u, v, w;
cin >> u >> v >> w;
dist[u][v] = min(dist[u][v], w);
}
for (int x = 1; x <= n; x++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) dist[i][j] = min(dist[i][j], dist[i][x] + dist[x][j]);
int lb = 0, rb = INF;
while (lb < rb) {
int mid = (lb + rb + 1) / 2;
if (check(mid)) lb = mid;
else rb = mid - 1;
}
cout << lb << '\n';
}
# | 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... |