이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll inf = 1ll << 60;
const int N = 101, K = 1001;
int b[N][K], s[N][K], c[N][N];
ll t[N][N];
int n, m, k;
bool check(ll mid){
ll mi[N][N];
for (int i = 1; i <= n; i++){
for (int j = 1; j <= n; j++){
if (t[i][j] < inf / mid) mi[i][j] = t[i][j] * mid - c[i][j];
else mi[i][j] = inf;
}
}
for (int i = 1; i <= n; i++){
for (int u = 1; u <= n; u++){
for (int v = 1; v <= n; v++){
mi[u][v] = min(mi[u][v], mi[u][i] + mi[i][v]);
}
}
}
for (int i = 1; i <= n; i++) if (mi[i][i] <= 0) return true;
return false;
}
int main(){
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++){
for (int j = 0; j < k; j++) cin >> b[i][j] >> s[i][j];
}
for (auto &i : t) for (ll &j : i) j = inf; //!!!
for (int i = 0; i < m; i++){
int u, v, _t;
cin >> u >> v >> _t;
t[u][v] = _t;
}
for (int i = 1; i <= n; i++){
for (int j = 1; j <= n; j++){
c[i][j] = 0;
for (int _k = 0; _k < k; _k++)
if (~s[j][_k] and ~b[i][_k]) c[i][j] = max(c[i][j], s[j][_k] - b[i][_k]);
}
}
for (int i = 1; i <= n; i++){
for (int u = 1; u <= n; u++){
for (int v = 1; v <= n; v++){
t[u][v] = min(t[u][v], t[u][i] + t[i][v]);
}
}
}
ll l = 0, r = inf;
while (l < r){
ll mid = l + r >> 1;
if (check(mid)) l = mid + 1;
else r = mid;
}
cout << l - 1 << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
merchant.cpp: In function 'int main()':
merchant.cpp:55:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | ll 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... |