Submission #723469

#TimeUsernameProblemLanguageResultExecution timeMemory
723469n0sk1llTravelling Merchant (APIO17_merchant)C++14
100 / 100
242 ms3424 KiB
#include <bits/stdc++.h> #define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0) #define mp make_pair #define xx first #define yy second #define pb push_back #define pf push_front #define popb pop_back #define popf pop_front #define all(x) x.begin(),x.end() #define ff(i,a,b) for (int i = a; i < b; i++) #define fff(i,a,b) for (int i = a; i <= b; i++) #define bff(i,a,b) for (int i = b-1; i >= a; i--) #define bfff(i,a,b) for (int i = b; i >= a; i--) using namespace std; long double typedef ld; unsigned int typedef ui; long long int typedef li; pair<int,int> typedef pii; pair<li,li> typedef pli; pair<ld,ld> typedef pld; vector<vector<int>> typedef graph; unsigned long long int typedef ull; //const int mod = 998244353; const int mod = 1000000007; //Note to self: Check for overflow int b[103][1003]; int s[103][1003]; li dist[103][103]; //shortest time li profit[103][103]; //koliko profitira od u do v (na pocetku uzima strogo shortest path) li g[103][103]; //ono cime svrsavamo zadatak int main() { FAST; int n,m,k; cin>>n>>m>>k; fff(i,1,n) fff(j,1,k) cin>>b[i][j]>>s[i][j]; fff(i,1,n) fff(j,1,n) dist[i][j]=mod; while (m--) { int u,v,w; cin>>u>>v>>w; dist[u][v]=w; } fff(pivot,1,n) { ff(i,1,pivot) ff(j,1,pivot) dist[i][j]=min(dist[i][j],dist[i][pivot]+dist[pivot][j]); ff(i,1,pivot) ff(j,1,pivot) dist[i][pivot]=min(dist[i][pivot],dist[i][j]+dist[j][pivot]); ff(i,1,pivot) ff(j,1,pivot) dist[pivot][j]=min(dist[pivot][j],dist[pivot][i]+dist[i][j]); //za svaki slucaj ponavljamo ff(i,1,pivot) ff(j,1,pivot) dist[i][j]=min(dist[i][j],dist[i][pivot]+dist[pivot][j]); ff(i,1,pivot) ff(j,1,pivot) dist[i][pivot]=min(dist[i][pivot],dist[i][j]+dist[j][pivot]); ff(i,1,pivot) ff(j,1,pivot) dist[pivot][j]=min(dist[pivot][j],dist[pivot][i]+dist[i][j]); } fff(i,1,n) dist[i][i]=0; fff(i,1,n) fff(j,1,n) if (dist[i][j]>mod-4) dist[i][j]=0; //samo ne... fff(predmet,1,k) fff(i,1,n) fff(j,1,n) if (s[j][predmet]>-1 && b[i][predmet]>-1) profit[i][j]=max(profit[i][j],(li)(s[j][predmet]-b[i][predmet])); /*fff(i,1,n) { fff(j,1,n) cout<<dist[i][j]<<" "; cout<<endl; } cout<<endl; fff(i,1,n) fff(j,1,n) { cout<<"immediate profit: ("<<i<<","<<j<<") = "<<profit[i][j]<<endl; }*/ int LL=0,RR=mod; while (RR-LL>1) { int delj=(LL+RR)/2; fff(i,1,n) fff(j,1,n) { if (dist[i][j]==0) g[i][j]=1e18; else g[i][j]=(li)delj*dist[i][j]-profit[i][j]; } /*cout<<delj<<":"<<endl; fff(i,1,n) { fff(j,1,n) cout<<g[i][j]<<" "; cout<<endl; }*/ ff(rep,0,3) fff(pivot,1,n) ff(_rep,0,2) { ff(i,1,pivot) ff(j,1,pivot) g[i][j]=min(g[i][j],g[i][pivot]+g[pivot][j]); ff(i,1,pivot) ff(j,1,pivot) g[i][pivot]=min(g[i][pivot],g[i][j]+g[j][pivot]); ff(i,1,pivot) ff(j,1,pivot) g[pivot][j]=min(g[pivot][j],g[pivot][i]+g[i][j]); } /*cout<<delj<<":"<<endl; fff(i,1,n) { fff(j,1,n) cout<<g[i][j]<<" "; cout<<endl; } cout<<endl;*/ li sta=1e18; fff(i,1,n) sta=min(sta,g[i][i]); if (sta<=0) LL=delj; else RR=delj; } cout<<LL; } //Note to self: Check for overflow /* 4 5 2 10 9 5 2 6 4 20 15 9 7 10 9 -1 -1 16 11 1 2 3 2 3 3 1 4 1 4 3 1 3 1 1 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...