Submission #132207

#TimeUsernameProblemLanguageResultExecution timeMemory
132207baluteshihTravelling Merchant (APIO17_merchant)C++14
100 / 100
102 ms4344 KiB
#pragma GCC optimize("O3") #include <bits/stdc++.h> #define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define pb push_back #define ET cout << "\n" #define ALL(v) v.begin(),v.end() #define MP make_pair #define F first #define S second #define MEM(i,j) memset(i,j,sizeof i) #define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;} using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const ll INF=2e9; pll buy[105][1005]; ll dis[105][105],earn[105][105],dp[105][105]; int main() {jizz ll n,m,k,a,b,w,l=0,r=1e9; cin >> n >> m >> k; for(int i=1;i<=n;++i) for(int j=0;j<k;++j) cin >> buy[i][j].F >> buy[i][j].S; for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) dis[i][j]=INF; while(m--) cin >> a >> b >> w,dis[a][b]=min(w,dis[a][b]); for(int k=1;k<=n;++k) for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]); for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) if(i!=j) for(int t=0;t<k;++t) if(~buy[i][t].F&&~buy[j][t].S) earn[i][j]=max(earn[i][j],buy[j][t].S-buy[i][t].F); while(l<r) { ll mid=(l+r)/2+1,tmp=-INF; for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) dp[i][j]=earn[i][j]-dis[i][j]*mid; for(int k=1;k<=n;++k) for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) dp[i][j]=max(dp[i][j],dp[i][k]+dp[k][j]); for(int i=1;i<=n;++i) tmp=max(tmp,dp[i][i]); if(tmp>=0) l=mid; else r=mid-1; } cout << l << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...