Submission #374227

#TimeUsernameProblemLanguageResultExecution timeMemory
374227ivan_tudorTravelling Merchant (APIO17_merchant)C++14
0 / 100
4 ms748 KiB
#include<bits/stdc++.h> using namespace std; const long long N = 105; long long mind[N][N]; long long maxp[N][N]; double newc[N][N]; long long b[N][1005]; long long s[N][1005]; double dst[N]; long long n; bool check(double R){ if(R == 0.5) cerr<<"-1\n";; for(long long i =1 ; i<=n;i++) for(long long j =1 ; j<=n;j++){ if(mind[i][j] == LLONG_MAX) newc[i][j] = INT_MAX; else newc[i][j] = 1.0 * R * mind[i][j] - maxp[i][j]; } for(long long i=1;i<=n;i++) dst[i] = INT_MAX; 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(newc[i][j] != INT_MAX && dst[i] != INT_MAX && 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(newc[i][j] != INT_MAX && dst[i] != INT_MAX && 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] = LLONG_MAX; 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][k] != LLONG_MAX && mind[k][j] != LLONG_MAX && 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 = -1LL<<49; for(long long p2 = 1LL<<50; p2 > 0; p2/=2){ if(check(pas + p2)) pas +=p2; } if(check(pas + 0.999999) == true) pas++; cout<<pas; return 0; }

Compilation message (stderr)

merchant.cpp: In function 'int main()':
merchant.cpp:40:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   40 |   freopen(".in","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...