제출 #309793

#제출 시각아이디문제언어결과실행 시간메모리
309793vipghn2003여행하는 상인 (APIO17_merchant)C++14
0 / 100
258 ms3452 KiB
#include<bits/stdc++.h> #define int long long #define pii pair<int,int> #define fi first #define se second #define mp make_pair using namespace std; const int N=105; const int K=1005; int n,m,k,d[N][N],buy[N][K],sell[N][K],opt[N][N],w[N][N]; bool check(int lim) { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { w[i][j]=-1e18; for(int u=1;u<=n;u++) { if(d[i][u]==-1||d[u][j]==-1) continue; int dist=d[i][u]+d[u][j]; int gain=opt[u][j]; w[i][j]=max(w[i][j],gain-dist*lim); } } } for(int k=1;k<=n;k++) { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { w[i][j]=max(w[i][j],w[i][k]+w[k][j]); if(w[i][i]>=0) return true; } } } return false; } main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); memset(d,-1,sizeof d); cin>>n>>m>>k; for(int i=1;i<=n;i++) { for(int j=1;j<=k;j++) cin>>buy[i][j]>>sell[i][j]; } while(m--) { int u,v,w; cin>>u>>v>>w; d[u][v]=w; } for(int u=1;u<=n;u++) { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(d[i][u]==-1||d[u][j]==-1) continue; int val=d[i][u]+d[u][j]; if(d[i][j]==-1||d[i][j]>val) d[i][j]=val; } } } for(int u=1;u<=n;u++) { for(int v=1;v<=n;v++) { opt[u][v]=0; for(int item=1;item<=k;item++) { if(buy[u][item]==-1||sell[v][item]==-1) continue; opt[u][v]=max(opt[u][v],sell[v][item]-buy[u][item]); } } } long long l=1,r=1e18,res=0; while(l<=r) { long long mid=(l+r)/2; if(check(mid)) { res=mid; l=mid+1; } else r=mid-1; } cout<<res; }

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

merchant.cpp:43:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   43 | main()
      |      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...