Submission #374242

#TimeUsernameProblemLanguageResultExecution timeMemory
374242ivan_tudorTravelling Merchant (APIO17_merchant)C++14
100 / 100
154 ms4332 KiB
#include<bits/stdc++.h> using namespace std; const long long N = 105; long long mind[N][N]; long long maxp[N][N]; long long newc[N][N]; long long b[N][1005]; long long s[N][1005]; long long n; bool check(long long R){ for(long long i =1 ; i<=n;i++) for(long long j =1 ; j<=n;j++){ newc[i][j] = maxp[i][j] - R * mind[i][j]; } for(long long k = 1; k <=n;k++){ for(long long i = 1; i<=n;i++) for(long long j =1 ; j<=n;j++){ if(newc[i][k] + newc[k][j] > newc[i][j]) newc[i][j] = newc[i][k] + newc[k][j]; } } for(long long i =1 ; i<=n;i++){ if(newc[i][i] >=0) return true; } return false; } int main() { //freopen(".in","r",stdin); ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); long long m, k; cin>>n>>m>>k; for(long long i=1;i<=n;i++){ for(long long j = 1; j<=k;j++) cin>>b[i][j]>>s[i][j]; } for(long long i = 1; i<=n;i++) for(long long j = 1; j<=n;j++) mind[i][j] = INT_MAX; for(long long i = 1; i<=m;i++){ long long x, y, d; cin>>x>>y>>d; mind[x][y] = d; } for(long long k = 1 ; k<=n;k++){ for(long long i =1 ; i<=n;i++) for(long long j =1 ; j<=n;j++){ if(mind[i][j] > mind[i][k] + mind[k][j]) mind[i][j] = mind[i][k] + mind[k][j]; } } for(long long i = 1; i<=n;i++){ for(long long j = 1; j<=n;j++){ maxp[i][j] = 0; for(long long l = 1; l<=k;l++){ if(b[i][l] == -1 || s[j][l] == -1) continue; maxp[i][j] = max(maxp[i][j], s[j][l] - b[i][l]); } } } long long pas = 0; for(long long p2 = 1LL<<30; p2 > 0; p2/=2){ if(check(pas + p2)) pas +=p2; } cout<<pas; 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...