Submission #402140

#TimeUsernameProblemLanguageResultExecution timeMemory
402140juggernautTravelling Merchant (APIO17_merchant)C++17
100 / 100
115 ms3392 KiB
#include<bits/stdc++.h> #define fr first #define sc second using namespace std; void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);} typedef long long ll; #define USING_ORDERED_SET 0 #if USING_ORDERED_SET #include<bits/extc++.h> using namespace __gnu_pbds; template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; #endif template<class T>void umax(T &a,T b){if(a<b)a=b;} template<class T>void umin(T &a,T b){if(b<a)a=b;} #ifdef IOI2021SG #define printl(args...)printf(args) #else #define printl(args...)((void)0) #endif const ll inf=1e18; const int N=105; const int K=1050; int b[N][K],s[N][K],p[N][N]; ll dist[N][N],work[N][N]; int main(){ int n,m,k,u,v; scanf("%d %d %d",&n,&m,&k); for(int i=1;i<=n;i++)for(int j=1;j<=k;j++)scanf("%d %d",&b[i][j],&s[i][j]); for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)for(int l=1;l<=k;l++)if(b[i][l]!=-1&&s[j][l]!=-1)p[i][j]=max(p[i][j],s[j][l]-b[i][l]); for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)dist[i][j]=inf; for(int i=1;i<=m;i++)scanf("%d %d",&u,&v),scanf("%lld",&dist[u][v]); for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)for(int l=1;l<=n;l++)dist[j][l]=min(dist[j][l],dist[j][i]+dist[i][l]); int r=1e9,l=1,mid,ans=0; while(l<=r){ mid=r+l>>1; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) work[i][j]=(ll)mid*min(dist[i][j],inf/mid)-p[i][j]; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) for(int l=1;l<=n;l++) work[j][l]=min(work[j][l],work[j][i]+work[i][l]); bool ok=0;for(int i=1;i<=n;i++) ok|=work[i][i]<=0; if(ok) ans=mid,l=mid+1; else r=mid-1; } printf("%d",ans); }

Compilation message (stderr)

merchant.cpp: In function 'int main()':
merchant.cpp:35:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |   mid=r+l>>1;
      |       ~^~
merchant.cpp: In function 'void usaco(std::string)':
merchant.cpp:5:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:5:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp: In function 'int main()':
merchant.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |  scanf("%d %d %d",&n,&m,&k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~
merchant.cpp:28:49: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |  for(int i=1;i<=n;i++)for(int j=1;j<=k;j++)scanf("%d %d",&b[i][j],&s[i][j]);
      |                                            ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:31:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  for(int i=1;i<=m;i++)scanf("%d %d",&u,&v),scanf("%lld",&dist[u][v]);
      |                       ~~~~~^~~~~~~~~~~~~~~
merchant.cpp:31:49: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  for(int i=1;i<=m;i++)scanf("%d %d",&u,&v),scanf("%lld",&dist[u][v]);
      |                                            ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...