이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
int n,m,k;
int store[105][1005][2];
int dist[105][105],prof[105][105];
int best[105][105][2];
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> k;
for(int i=1;i<=n;i++){
for(int j=1;j<=k;j++){
cin >> store[i][j][0] >> store[i][j][1];
if(store[i][j][0]==-1){
store[i][j][0] = 2e9;
}
if(store[i][j][1]==-1){
store[i][j][1] = -1;
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i!=j){
dist[i][j] = 2e18;
}
}
}
for(int i=1;i<=m;i++){
int a,b,c;
cin >> a >> b >> c;
dist[a][b] = c;
}
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
prof[i][j] = -2e9;
for(int k=1;k<=n;k++){
prof[i][j] = max(prof[i][j],store[i][k][1]-store[j][k][0]);
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
best[i][j][0] = prof[i][j];
best[i][j][1] = dist[i][j];
}
}
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(best[i][j][1]==0){
best[i][j][0] = best[i][k][0]+best[k][j][0];
best[i][j][1] = best[i][k][1]+best[k][j][1];
}
else{
if(best[i][k][1]+best[k][j][1]==0){
continue;
}
int a = best[i][k][0]+best[k][j][0], b = best[i][k][1]+best[k][j][1];
if(a*best[i][j][1]>b*best[i][j][0]){
best[i][j][0] = a;
best[i][j][1] = b;
}
}
}
}
}
int ans=0;
for(int i=1;i<=n;i++){
if(best[i][i][1]){
ans = max(ans,best[i][i][0]/best[i][i][1]);
}
}
cout << ans << "\n";
return 0;
}
# | 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... |