이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
const ll inf = 5e14 + 5;
const int nmax = 105;
void fw(int n, ll dist[nmax][nmax]) {
for(int h = 0; h < n; h++) {
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++)
dist[i][j] = min(dist[i][j], dist[i][h] + dist[h][j]);
}
}
}
void fwmx(int n, ll dist[nmax][nmax]) {
for(int h = 0; h < n; h++) {
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++)
dist[i][j] = max(dist[i][j], dist[i][h] + dist[h][j]);
}
}
}
void print(int n, ll dist[nmax][nmax]) {
//for(int i = 0; i < n; i++) {
//for(int j = 0; j < n; j++)
//cerr << dist[i][j] << ' ';
//cerr << '\n';
//}
return;
}
ll dist[nmax][nmax], cost[nmax][nmax], alter[nmax][nmax];
ll buy[nmax][nmax], sell[nmax][nmax];
bool check(int n, int coef) {
//cerr << "Alter with coef " << coef << '\n';
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++)
alter[i][j] = cost[i][j] - dist[i][j] * coef;
}
print(n, alter);
fwmx(n, alter);
for(int i = 0; i < n; i++) {
if(alter[i][i] >= 0)
return 1;
}
return 0;
}
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] = -inf;
}
}
for(int i = 0; i< n; i++)
for(int j = 0; j < n; j++)
dist[i][j] = inf;
for(int i = 0, x, y, c; i < m; i++)
cin >> x >> y >> c, --x, --y, dist[x][y] = min(dist[x][y], c);
fw(n, dist);
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
cost[i][j] = 0;
for(int h = 0; h < k; h++)
cost[i][j] = max(cost[i][j], sell[j][h] - buy[i][h]);
}
}
//cerr << "Cost:\n";
print(n, cost);
//cerr << "Dist:\n";
print(n, dist);
int l = 0, r = 1e9 + 5, mid;
while(r - l > 1) {
mid = l + r >> 1;
if(check(n, mid))
l = mid;
else
r = mid;
}
cout << l << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
merchant.cpp: In function 'int main()':
merchant.cpp:83:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
83 | mid = l + r >> 1;
| ~~^~~
# | 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... |