Submission #594857

#TimeUsernameProblemLanguageResultExecution timeMemory
594857penguinhackerTravelling Merchant (APIO17_merchant)C++17
100 / 100
96 ms3356 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array const ll INF=1e18; int n, m, k, b[100][1000], s[100][1000], profit[100][100]; ll d[100][100], dp[100][100]; bool ok(int x) { for (int i=0; i<n; ++i) for (int j=0; j<n; ++j) dp[i][j]=i==j||d[i][j]>=INF?-INF:profit[i][j]-x*d[i][j]; for (int l=0; l<n; ++l) for (int i=0; i<n; ++i) for (int j=0; j<n; ++j) dp[i][j]=max(dp[i][j], min(INF, dp[i][l]+dp[l][j])); for (int i=0; i<n; ++i) if (dp[i][i]>=0) return 1; return 0; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> k; for (int i=0; i<n; ++i) for (int j=0; j<k; ++j) cin >> b[i][j] >> s[i][j]; memset(d, 0x3f, sizeof(d)); for (int i=0; i<n; ++i) d[i][i]=0; for (int i=0; i<m; ++i) { int u, v, w; cin >> u >> v >> w, --u, --v; d[u][v]=w; } for (int i=0; i<n; ++i) for (int j=0; j<n; ++j) for (int l=0; l<k; ++l) if (b[i][l]!=-1&&s[j][l]!=-1) profit[i][j]=max(profit[i][j], s[j][l]-b[i][l]); for (int l=0; l<n; ++l) for (int i=0; i<n; ++i) for (int j=0; j<n; ++j) d[i][j]=min(d[i][j], d[i][l]+d[l][j]); int lb=0, rb=1e9; while(lb<rb) { int mid=(lb+rb+1)/2; if (ok(mid)) lb=mid; else rb=mid-1; } cout << lb; 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...