Submission #487583

#TimeUsernameProblemLanguageResultExecution timeMemory
487583leakedTravelling Merchant (APIO17_merchant)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define f first #define s second #define vec vector #define pb push_back #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define pw(x) (1LL<<(x)) #define sz(x) (int)(x).size() #define fast_iati ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);} template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);} typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll>pll; const int N=201; const int K=2001; const ll inf=1e16; int b[N][K],s[N][K]; ll dst[N][N]; ll mx[N][N]; signed main(){ fast_iati; int n,m,k; cin>>n>>m>>k; for(int i=0;i<n;i++){ for(int j=0;j<k;j++){ cin>>b[i][j]>>s[i][j]; } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(i==j) continue; for(int t=0;t<k;t++){ if(b[i][t]==-1 || s[j][t]==-1) continue; umax(mx[i][j],(ll)-b[i][t]+s[j][t]); } } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++) dst[i][j]=inf; dst[i][i]=0; } for(int i=0;i<m;i++){ int v,u,w; cin>>v>>u>>w;--v;--u; umin(dst[v][u],(ll)w); } for(int t=0;t<n;t++){ for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ umin(dst[i][j],dst[i][t]+dst[t][j]); } } } auto check=[&](ll x){ vec<vec<ll>>f(n,vec<ll>(n,-inf)); int iter=n; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(dst[i][j]<=inf/x && i!=j){ umax(f[i][j],mx[i][j]-1ll*x*dst[i][j]); } } } vec<ll>dp(n,-inf); for(int j=1;j<n;j++) umax(dp[j],f[i][j]); while(iter--){ int ok=0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(umax(dp[j],dp[i]+f[i][j])) ok=1; } } if(!ok){ break; } if(iter==0) return 1; } return (dp[0]>=0); }; // cout<<check(3); // return 0; ll l=1,r=inf; while(l!=r){ ll mid=(l+r)/2; if(check(mid)) l=mid+1; else r=mid; } cout<<l-1; return 0; }

Compilation message (stderr)

merchant.cpp: In lambda function:
merchant.cpp:71:43: error: 'i' was not declared in this scope
   71 |         for(int j=1;j<n;j++) umax(dp[j],f[i][j]);
      |                                           ^
merchant.cpp:84:22: error: inconsistent types 'int' and 'bool' deduced for lambda return type
   84 |         return (dp[0]>=0);
      |                ~~~~~~^~~~