Submission #374217

#TimeUsernameProblemLanguageResultExecution timeMemory
374217ivan_tudorTravelling Merchant (APIO17_merchant)C++14
0 / 100
89 ms3436 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 dst[N]; 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 i=1;i<=n;i++) dst[i] = 1LL<<60; dst[1] = 0; for(long long nr = 1; nr <n;nr++){ for(long long i = 1; i<=n;i++) for(long long j =1 ; j<=n;j++){ if(dst[i] + newc[i][j] < dst[j]) dst[j] = dst[i] + newc[i][j]; } } for(long long i =1 ; i<=n;i++){ for(long long j =1 ; j<=n;j++) if(dst[i] + newc[i][j] < dst[j]) 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] = 1<<28; for(long long i = 1; i<=n;i++) mind[i][i] = 0; 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 l = 0, r = 1<<30; while(l < r){ long long mid = (l + r)/2; if(check(mid)) r = mid; else l = mid + 1; } cout<<l + 1; 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...