Submission #289760

#TimeUsernameProblemLanguageResultExecution timeMemory
289760wwddTravelling Merchant (APIO17_merchant)C++14
100 / 100
119 ms4344 KiB
// i don't understand #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INFL = 2e18; const int MN = 105; const int MK = 1010; ll am[MN][MN]; ll pr[MN][MN]; ll ro[MN][MN]; ll bro[MN][MK],slo[MN][MK]; int main() { ios::sync_with_stdio(0);cin.tie(0); ll n,m,ks; cin >> n >> m >> ks; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { am[i][j] = INFL; } } for(int i=0;i<n;i++) { for(int j=0;j<ks;j++) { cin >> bro[i][j] >> slo[i][j]; } } for(int i=0;i<m;i++) { ll a,b,c; cin >> a >> b >> c; a--;b--; am[a][b] = c; } for(int k=0;k<n;k++) { for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { am[i][j] = min(am[i][j],am[i][k]+am[k][j]); } } } memset(pr,0,sizeof(pr)); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { for(int k=0;k<ks;k++) { if(slo[j][k] == -1) {continue;} if(bro[i][k] == -1) {continue;} pr[i][j] = max(pr[i][j],slo[j][k]-bro[i][k]); } } } ll st = 1,ed = 1e9+2; ll ls = 0; while(st <= ed) { ll md = (st+ed)/2; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i == j) { ro[i][j] = -1; } else if(am[i][j] == INFL) { ro[i][j] = -INFL; } else { ro[i][j] = pr[i][j]-md*am[i][j]; } } } for(int k=0;k<n;k++) { for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { ro[i][j] = max(ro[i][j],ro[i][k]+ro[k][j]); ro[i][j] = min(ro[i][j],INFL); } } } bool lol = false; for(int i=0;i<n;i++) { if(ro[i][i] >= 0) { lol = true;break; } } if(lol) { ls = md; st = md+1; } else { ed = md-1; } } cout << ls << '\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...