# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
221636 | MKopchev | 여행하는 상인 (APIO17_merchant) | C++14 | 122 ms | 3448 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int nmax=1e2+5,kmax=1e3+5,inf=1e9+42;
int n,m,k;
int cost[2][nmax][kmax];
int dist[nmax][nmax];
int max_gain[nmax][nmax];
long long current_edges[nmax][nmax],current_dists[nmax][nmax];
bool can(int test)
{
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
current_edges[i][j]=max_gain[i][j]-1LL*test*dist[i][j];
current_dists[i][j]=current_edges[i][j];
}
for(int p=1;p<=n;p++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
current_dists[i][j]=max(current_dists[i][j],current_dists[i][p]+current_dists[p][j]);
for(int i=1;i<=n;i++)
if(current_dists[i][i]>=0)return 1;
return 0;
}
int main()
{
scanf("%i%i%i",&n,&m,&k);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
dist[i][j]=inf;
for(int i=1;i<=n;i++)
for(int j=1;j<=k;j++)
for(int t=0;t<2;t++)
scanf("%i",&cost[t][i][j]);
int u,v,c;
for(int i=1;i<=m;i++)
{
scanf("%i%i%i",&u,&v,&c);
dist[u][v]=min(dist[u][v],c);
}
for(int p=1;p<=n;p++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
dist[i][j]=min(dist[i][j],dist[i][p]+dist[p][j]);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(dist[i][j]!=inf)
{
for(int p=1;p<=k;p++)
if(cost[0][i][p]!=-1&&cost[1][j][p]!=-1)max_gain[i][j]=max(max_gain[i][j],cost[1][j][p]-cost[0][i][p]);
}
int ok=0,not_ok=inf;
while(not_ok-ok>1)
{
int av=(ok+not_ok)/2;
if(can(av))ok=av;
else not_ok=av;
}
printf("%i\n",ok);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |