Submission #692881

#TimeUsernameProblemLanguageResultExecution timeMemory
692881penguin133Travelling Merchant (APIO17_merchant)C++17
100 / 100
84 ms5036 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pi pair<int, int> #define pii pair<int, pi> #define fi first #define se second #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #endif int B[105][10005], S[105][10005], adj[105][105], prof[105][105], n, m, kk, adj2[105][105]; void solve(){ cin >> n >> m >> kk; for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)adj[i][j] = 1e18, adj[i][i] = 0; for(int i=1;i<=n;i++){ for(int j=1;j<=kk;j++)cin >> B[i][j] >> S[i][j]; } while(m--){ int x, y, z; cin >> x >> y >> z; adj[x][y] = min(adj[x][y], z); } for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]); for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){ for(int k=1;k<=kk;k++)if(B[i][k] != -1 && S[j][k] != -1)prof[i][j] = max(prof[i][j], S[j][k] - B[i][k]); } int lo = 1, hi = 1e9, ans = 0; while(lo <= hi){ int mid = (lo + hi) >> 1; for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)adj2[i][j] = 1e18; for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(i != j && adj[i][j] != 1e18)adj2[i][j] = min(adj2[i][j], mid * adj[i][j] - prof[i][j]); for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)adj2[i][j] = min(adj2[i][j], adj2[i][k] + adj2[k][j]); bool f = 0; for(int i=1;i<=n;i++)if(adj2[i][i] <= 0)f = 1; if(f)ans = mid, lo = mid + 1; else hi = mid - 1; } cout << ans; } main(){ ios::sync_with_stdio(0);cin.tie(0); int tc = 1; //cin >> tc; for(int tc1=1;tc1<=tc;tc1++){ // cout << "Case #" << tc1 << ": "; solve(); } }

Compilation message (stderr)

merchant.cpp:42:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   42 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...