Submission #101110

#TimeUsernameProblemLanguageResultExecution timeMemory
101110ae04071Travelling Merchant (APIO17_merchant)C++11
0 / 100
46 ms1280 KiB
#include <bits/stdc++.h> using namespace std; using lli=long long; int n,m,k; lli adj[101][101], car[101][101], dist[100]; int s[100][1000],b[100][1000]; bool check(int C) { for(int t=0;t<n;t++) { int chg=0; for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(adj[i][j]) { if(dist[j] > dist[i] + C*adj[i][j] - car[i][j]) { chg=1; dist[j] = dist[i] + C*adj[i][j] - car[i][j]; } } if(!chg) break; if(t==n-1) return true; } return false; } int main() { scanf("%d%d%d",&n,&m,&k); for(int i=0;i<n;i++) { for(int j=0;j<k;j++) scanf("%d%d",&b[i][j], &s[i][j]); } for(int i=0;i<m;i++) { int a,b; lli c; scanf("%d%d%lld",&a,&b,&c); a--;b--; adj[a][b] = c; } for(int k=0;k<n;k++) for(int i=0;i<n;i++) for(int j=0;j<n;j++) { if(adj[i][k] && adj[k][j] && (!adj[i][j] || adj[i][j] > adj[i][k]+adj[k][j])) { adj[i][j] = adj[i][k]+adj[k][j]; } } for(int i=0;i<n;i++)for(int j=0;j<n;j++) if(adj[i][j]) { int ad=0; for(int t=0;t<k;t++) if(s[j][t]!=-1 && b[i][t]!=-1) { ad=max(ad,s[j][t]-b[i][t]); } car[i][j] = ad; } int lo=-1,up=1000000000; while(up-lo>1) { int md=(lo+up)>>1; if(check(md)) lo=md; else up=md; } printf("%d\n",lo+1); return 0; }

Compilation message (stderr)

merchant.cpp: In function 'int main()':
merchant.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&n,&m,&k);
     ~~~~~^~~~~~~~~~~~~~~~~~~
merchant.cpp:26:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         for(int j=0;j<k;j++) scanf("%d%d",&b[i][j], &s[i][j]);
                              ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%lld",&a,&b,&c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...