Submission #656979

#TimeUsernameProblemLanguageResultExecution timeMemory
656979IliyaTravelling Merchant (APIO17_merchant)C++17
0 / 100
93 ms3396 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1e2 + 2; const int K = 1e3 + 3; long long buy[N][K] , sel[N][K] , d[N][N] , sod[N][N] , dp[N][N] , val; int n , m , k; bool f(int x){ for(int u = 1 ; u <= n ; u++) for(int v = 1 ; v <= n ; v++) if(d[u][v] != val) dp[u][v] = d[u][v] * x - sod[u][v]; for(int w = 1 ; w <= n ; w++) for(int u = 1 ; u <= n ; u++) for(int v = 1 ; v <= n ; v++) dp[u][v] = min(dp[u][v] , dp[u][w] + dp[w][v]); bool ch = false; for(int u = 1 ; u <= n ; u++) if(dp[u][u] <= 0) ch = true; return ch; } int main(){ ios::sync_with_stdio(0), cout.tie(0), cin.tie(0); memset(buy , -1 , sizeof(buy)); memset(sel , -1 , sizeof(sel)); memset(d , 63 , sizeof(d)); val = d[0][0]; cin >> n >> m >> k; for(int i = 1 ; i <= n ; i++) for(int j = 1 ; j <= k ; j++) cin >> buy[i][j] >> sel[i][j]; for(int i = 1 ; i <= n ; i++) for(int j = 1 ; j <= n ; j++) for(int p = 1 ; p <= k ; p++) if(buy[i][p] != -1 && sel[j][p] != -1) sod[i][j] = max(sod[i][j] , sel[j][p] - buy[i][p]); for(int i = 1 ; i <= m ; i++){ int u , v; long long w; cin >> u >> v >> w; d[u][v] = w; } for(int w = 1 ; w <= n ; w++) for(int u = 1 ; u <= n ; u++) for(int v = 1 ; v <= n ; v++) d[u][v] = min(d[u][v] , d[u][w] + d[w][v]); int low = 0 , high = 1e9; while(high - low > 1){ int mid = (high + low) >> 1; if(f(mid)) low = mid; else high = mid; } cout << low << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...