제출 #485663

#제출 시각아이디문제언어결과실행 시간메모리
485663MilosMilutinovic여행하는 상인 (APIO17_merchant)C++14
100 / 100
84 ms4484 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector<int> VI; typedef long long ll; typedef pair<int,int> PII; typedef double db; mt19937 mrand(random_device{}()); const ll mod=1000000007; const ll mod2=998244353; int rnd(int x) { return mrand() % x;} ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} // head const int N=1010; int n,m,k,b[N][N],s[N][N],a[N][N]; ll d[N][N]; db dis[N][N]; bool check(ll x) { rep(i,1,n+1) rep(j,1,n+1) dis[i][j]=x*min((ll)d[i][j],(ll)1e18/x)-a[i][j]; rep(p,1,n+1) rep(i,1,n+1) rep(j,1,n+1) dis[i][j]=min(dis[i][j],dis[i][p]+dis[p][j]); rep(i,1,n+1) if (dis[i][i]<=0) return 1; return 0; } int main() { scanf("%d%d%d",&n,&m,&k); rep(i,1,n+1) rep(j,1,k+1) scanf("%d%d",&b[i][j],&s[i][j]); rep(i,1,n+1) rep(j,1,n+1) d[i][j]=(ll)1e18; rep(i,1,m+1) { int u,v,w; scanf("%d%d%d",&u,&v,&w); d[u][v]=min(d[u][v],(ll)w); } rep(p,1,n+1) rep(i,1,n+1) rep(j,1,n+1) d[i][j]=min(d[i][j],d[i][p]+d[p][j]); rep(i,1,n+1) rep(j,1,n+1) rep(p,1,k+1) { if (b[i][p]!=-1&&s[j][p]!=-1) a[i][j]=max(a[i][j],s[j][p]-b[i][p]); } ll l=1,r=1e9,ans=0; while (l<=r) { ll md=l+r>>1; if (check(md)) ans=md,l=md+1; else r=md-1; } printf("%lld",ans); }

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

merchant.cpp: In function 'int main()':
merchant.cpp:50:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   50 |   ll md=l+r>>1;
      |         ~^~
merchant.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |  scanf("%d%d%d",&n,&m,&k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
merchant.cpp:37:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |  rep(i,1,n+1) rep(j,1,k+1) scanf("%d%d",&b[i][j],&s[i][j]);
      |                            ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |   scanf("%d%d%d",&u,&v,&w);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...