Submission #309922

#TimeUsernameProblemLanguageResultExecution timeMemory
309922vipghn2003Travelling Merchant (APIO17_merchant)C++14
100 / 100
135 ms2296 KiB
#include<bits/stdc++.h> #define int long long #define pii pair<int,int> #define fi first #define se second #define mp make_pair using namespace std; const int N=105; const int K=1005; int n,m,k,d[N][N],buy[N][K],sell[N][K],opt[N][N],w[N][N]; bool check(int lim) { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { w[i][j]=-3e18; if(d[i][j]==3e18) continue; int dist=d[i][j]; int gain=opt[i][j]; w[i][j]=gain-dist*lim; } } for(int k=1;k<=n;k++) { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { w[i][j]=max(w[i][j],w[i][k]+w[k][j]); if(w[i][j]>=3e18) w[i][j]=3e18; } } } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) if(w[i][j]+w[j][i]>=0) return true; } return false; } main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin>>n>>m>>k; for(int i=1;i<=n;i++) { for(int j=1;j<=k;j++) cin>>buy[i][j]>>sell[i][j]; } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) d[i][j]=3e18; } while(m--) { int u,v,w; cin>>u>>v>>w; d[u][v]=w; } for(int u=1;u<=n;u++) { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { int val=d[i][u]+d[u][j]; d[i][j]=min(d[i][j],val); } } } for(int u=1;u<=n;u++) { for(int v=1;v<=n;v++) { opt[u][v]=0; for(int item=1;item<=k;item++) { if(buy[u][item]==-1||sell[v][item]==-1) continue; opt[u][v]=max(opt[u][v],sell[v][item]-buy[u][item]); } } } int l=1,r=1e9,res=0; while(l<=r) { int mid=(l+r)/2; if(check(mid)) { res=mid; l=mid+1; } else r=mid-1; } cout<<res; }

Compilation message (stderr)

merchant.cpp:44:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   44 | main()
      |      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...