Submission #57075

#TimeUsernameProblemLanguageResultExecution timeMemory
57075XellosTravelling Merchant (APIO17_merchant)C++14
100 / 100
894 ms14504 KiB
#include <bits/stdc++.h> // iostream is too mainstream #include <cstdio> // bitch please #include <iostream> #include <algorithm> #include <cstdlib> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <list> #include <cmath> #include <iomanip> #include <time.h> #define dibs reserve #define OVER9000 1234567890 #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++) #define tisic 47 #define soclose 1e-8 #define chocolate win // so much chocolate #define patkan 9 #define ff first #define ss second #define abs(x) ((x < 0)?-(x):x) #define uint unsigned int #define dbl long double #define pi 3.14159265358979323846 using namespace std; // mylittledoge typedef long long cat; #ifdef DONLINE_JUDGE // palindromic tree is better than splay tree! #define lld I64d #endif int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); int N,M,K; cin >> N >> M >> K; vector< vector<cat> > B(N,vector<cat>(K)), S(N,vector<cat>(K)); for(int i =0; i < N; i++) for(int j =0; j < K; j++) cin >> B[i][j] >> S[i][j]; vector< vector<cat> > D(N,vector<cat>(N,1e18)); for(int i =0; i < N; i++) D[i][i] =0; for(int i =0; i < M; i++) { int a,b,c; cin >> a >> b >> c; D[a-1][b-1] =min(D[a-1][b-1],1LL*c);} for(int k =0; k < N; k++) for(int i =0; i < N; i++) for(int j =0; j < N; j++) D[i][j] =min(D[i][j],D[i][k]+D[k][j]); vector< vector<cat> > gain(N,vector<cat>(N,0)); for(int i =0; i < N; i++) for(int k =0; k < K; k++) if(B[i][k] != -1) for(int j =0; j < N; j++) if(S[j][k] > B[i][k]) gain[i][j] =max(gain[i][j],S[j][k]-B[i][k]); cat ansA =0, ansB =OVER9000; while(ansB-ansA > 1) { int r =(ansA+ansB)/2; vector< vector<cat> > cost(N,vector<cat>(N,-1e18)); for(int i =0; i < N; i++) for(int j =0; j < N; j++) if(D[i][j] < 1e10) cost[i][j] =gain[i][j]-r*D[i][j]; for(int a =0; a < 10; a++) { bool br =false; for(int i =0; i < N; i++) for(int j =0; j < N; j++) if(i != j) if(cost[i][j]+cost[j][i] >= 0) br =true; if(br) break; vector< vector<cat> > cost_nw =cost; for(int i =0; i < N; i++) for(int j =0; j < N; j++) if(D[i][j] < 1e10) for(int k =0; k < N; k++) if(D[j][k] < 1e10) cost_nw[i][k] =max(cost_nw[i][k],cost[i][j]+cost[j][k]); cost =cost_nw;} bool ok =false; for(int i =0; i < N; i++) for(int j =0; j < N; j++) if(i != j) if(cost[i][j]+cost[j][i] >= 0) ok =true; if(ok) ansA =r; else ansB =r;} cout << ansA << "\n"; return 0;} // look at my code // my code is amazing
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...