제출 #101119

#제출 시각아이디문제언어결과실행 시간메모리
101119ae04071여행하는 상인 (APIO17_merchant)C++11
12 / 100
54 ms3068 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, bool f=false) { fill(dist, dist+n, 0); 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; } if(f) { for(int i=0;i<n;i++)for(int j=0;j<n;j++) if(adj[i][j] && adj[j][i]){ if(dist[i] + C*(adj[i][j]+adj[j][i]) - (car[i][j]+car[j][i]) == 0) return true; } return false; } else 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; } if(check(lo+1, true)) lo++; printf("%d\n",lo); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

merchant.cpp: In function 'int main()':
merchant.cpp:30: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:32: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:37: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...