Submission #172042

#TimeUsernameProblemLanguageResultExecution timeMemory
172042PajarajaTravelling Merchant (APIO17_merchant)C++17
100 / 100
234 ms4444 KiB
#include <bits/stdc++.h> #define MAXN 107 #define MAXK 1007 using namespace std; long long bp[MAXN][MAXK],sp[MAXN][MAXK],d[MAXN][MAXN],w[MAXN][MAXN],wb[MAXN][MAXN],dist[MAXN],dn[MAXN]; int n,m,a; void zvonocovek() { for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(i!=j && wb[i][j]) dist[j]=min(dist[j],dist[i]+wb[i][j]); } bool provera(long long k) { for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { if(40000000000000000LL/n<d[i][j]*k-w[i][j]) wb[i][j]=0; else wb[i][j]=n*(d[i][j]*k-w[i][j])-1; } dist[1]=0; for(int i=2;i<=n;i++) dist[i]=1000000000000000000LL; for(int i=1;i<=n;i++) zvonocovek(); for(int i=1;i<=n;i++) dn[i]=dist[i]; zvonocovek(); for(int i=1;i<=n;i++) if(dist[i]!=dn[i]) return true; return false; } long long binarna(long long l, long long r) { if(l==r) return l; long long s=(l+r+1)/2; if(provera(s)) return binarna(s,r); return binarna(l,s-1); } int main() { cin>>n>>m>>a; for(int i=1;i<=n;i++) for(int j=1;j<=a;j++) cin>>bp[i][j]>>sp[i][j]; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) d[i][j]=1000000000000000000LL; for(int i=1;i<=m;i++) { int t1,t2; long long t3; cin>>t1>>t2>>t3; d[t1][t2]=min(d[t1][t2],t3); } for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) for(int k=1;k<=n;k++) d[j][k]=min(d[j][k],d[j][i]+d[i][k]); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(i!=j) for(int k=1;k<=a;k++) if(bp[i][k]!=-1 && sp[j][k]!=-1) w[i][j]=max(w[i][j],sp[j][k]-bp[i][k]); //for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(i!=j) printf("%d %d %lld %lld\n",i,j,d[i][j],w[i][j]); printf("%lld",binarna(0,1000000000)); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...