# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
102000 | bakpark | Travelling Merchant (APIO17_merchant) | C++14 | 125 ms | 2168 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <algorithm>
#include <limits.h>
#include <memory.h>
using namespace std;
#define ll long long
int N,M,K;
ll B[101][1001], S[101][1001], T[101][101],val[101][101];
ll Q[101][101];
ll dist[101][101];
ll g(int st,int en,ll m,ll d){
return Q[st][en]-d*m;
}
bool f(ll m){
for(int i=1;i<=N;i++){
for(int j=1;j<=N;j++){
if(T[i][j]) {
dist[i][j] = T[i][j];
val[i][j] = g(i,j,m,T[i][j]);
}
else {
dist[i][j] = -1;
val[i][j] = LLONG_MIN;
}
}
}
for(int mid=1;mid<=N;mid++){
for(int st=1;st<=N;st++){
for(int en=1;en<=N;en++){
if(dist[st][mid]==-1||dist[mid][en]==-1) continue;
ll td = dist[st][mid]+dist[mid][en];
ll hval = max(g(st,en,m,td),val[st][mid]+val[mid][en]);
if(hval>val[st][en]){
dist[st][en] = td;
val[st][en] = hval;
}
}
}
for(int n=1;n<=N;n++){
if(val[n][n]>=0) return true;
}
}
return false;
}
int main(){
scanf("%d %d %d",&N,&M,&K);
for(int i=1;i<=N;i++){
for(int j=0;j<K+K;j++){
ll tmp;scanf("%lld",&tmp);
if(j&1) S[i][j/2+1] = tmp;
else B[i][j/2+1] = tmp;
}
}
for(int i=0;i<M;i++){
int a,b;
ll c;
scanf("%d %d %lld",&a,&b,&c);
T[a][b] = c;
}
for(int i=1;i<=N;i++){
for(int j=1;j<=N;j++){
for(int k=1;k<=K;k++){
if(i==j) continue;
if(B[i][k]>0&&S[j][k]>0)
Q[i][j] = max(Q[i][j],S[j][k]-B[i][k]);
}
}
}
ll l = 0,r = 1000000000,answ=0;
while(l<=r){
ll m = (l+r)>>1;
if(f(m)){
l = m+1;
answ = m;
}
else r = m-1;
}
printf("%lld",answ);
}
Compilation message (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... |