이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
int B[105][10005], S[105][10005], adj[105][105], prof[105][105], n, m, kk, adj2[105][105];
void solve(){
cin >> n >> m >> kk;
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)adj[i][j] = 1e18, adj[i][i] = 0;
for(int i=1;i<=n;i++){
for(int j=1;j<=kk;j++)cin >> B[i][j] >> S[i][j];
}
while(m--){
int x, y, z; cin >> x >> y >> z;
adj[x][y] = min(adj[x][y], z);
}
for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){
for(int k=1;k<=kk;k++)if(B[i][k] != -1 && S[j][k] != -1)prof[i][j] = max(prof[i][j], S[j][k] - B[i][k]);
}
int lo = 1, hi = 1e9, ans = 0;
while(lo <= hi){
int mid = (lo + hi) >> 1;
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)adj2[i][j] = 1e18;
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(i != j && adj[i][j] != 1e18)adj2[i][j] = min(adj2[i][j], mid * adj[i][j] - prof[i][j]);
for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)adj2[i][j] = min(adj2[i][j], adj2[i][k] + adj2[k][j]);
bool f = 0;
for(int i=1;i<=n;i++)if(adj2[i][i] <= 0)f = 1;
if(f)ans = mid, lo = mid + 1;
else hi = mid - 1;
}
cout << ans;
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int tc = 1;
//cin >> tc;
for(int tc1=1;tc1<=tc;tc1++){
// cout << "Case #" << tc1 << ": ";
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
merchant.cpp:42:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
42 | main(){
| ^~~~
# | 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... |