Submission #312758

#TimeUsernameProblemLanguageResultExecution timeMemory
312758KuuhakuTravelling Merchant (APIO17_merchant)C++17
21 / 100
99 ms1472 KiB
//Oct14 #define tasknames "merchant" #include <iostream> #include <stdio.h> #include <cstring> #include <algorithm> #include <vector> using namespace std; const int maxn = 105; int n, m, k, b[maxn][maxn*10], s[maxn][maxn*10]; long long a[maxn][maxn], d[maxn][maxn], vl[maxn][maxn]; void Enter() { cin>>n>>m>>k; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(i!=j)a[i][j]=3e18; for(int i=1;i<=n;i++) for(int j=1;j<=k;j++) cin>>b[i][j]>>s[i][j]; for(int i=1;i<=m;i++) { int u, v, w; cin>>u>>v>>w; a[u][v]=min(a[u][v],1ll*w); } } void Prepare() { for(int t=1;t<=n;t++) for(int i=1; i<=n;i++) for(int j=1;j<=n;j++) a[i][j]=min(a[i][j],a[i][t]+a[t][j]); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) for(int t=1;t<=k;t++) { if(b[i][t]==-1||s[j][t]==-1)continue; vl[i][j]=max(vl[i][j],1ll*s[j][t]-b[i][t]); } } bool Check(long long mid) { for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) d[i][j]=3e18; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { if(a[i][j]==3e18)continue; d[i][j]=min(d[i][j],a[i][j]*mid-vl[i][j]); } for(int i=1;i<=n;i++) d[i][i]=3e18; for(int t=1;t<=n;t++) for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) d[i][j]=min(d[i][j],d[i][t]+d[t][j]); if(d[i][i]<=0)return true; } return false; } void Solve() { long long l=0, r=1e11, mid; while(l<=r) { mid=(l+r)/2; if(Check(mid)) l=mid+1; else r=mid-1; } cout<<r; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if(fopen(tasknames".INP","r")) { freopen(tasknames".INP","r",stdin); freopen(tasknames".OUT","w",stdout); } Enter(); Prepare(); Solve(); }

Compilation message (stderr)

merchant.cpp: In function 'int main()':
merchant.cpp:87:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   87 |      freopen(tasknames".INP","r",stdin);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   88 |         freopen(tasknames".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...