Submission #914400

#TimeUsernameProblemLanguageResultExecution timeMemory
914400panTravelling Merchant (APIO17_merchant)C++17
100 / 100
124 ms4272 KiB
#include <bits/stdc++.h> //#include "bits_stdc++.h" #define f first #define s second #define mp make_pair #define pb push_back #define lb lower_bound #define ub upper_bound //#define input(x) scanf("%lld", &x); //#define print(x, y) printf("%lld%c", x, y); #define show(x) cerr << #x << " is " << x << endl; #define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl; #define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl; using namespace std; typedef long long ll; typedef long double ld; typedef pair<ld, ll> pd; typedef pair<string, ll> psl; typedef pair<ll, ll> pi; typedef pair<ll, pi> pii; vector<vector<ll> > adj; ll n, m ,k, x,y, z; ll buy[105][1005]; ll sell[105][1005]; ll p[105][105]; bool floydwarshall(ll mid) { vector<vector<ll> > dist; dist.assign(n+1, vector<ll> (n+1, LLONG_MAX)); for (ll i=1; i<=n;++i) { for (ll j=1; j<=n; ++j) { if (adj[i][j]==LLONG_MAX) dist[i][j] = LLONG_MAX; else dist[i][j] = min(dist[i][j], mid*adj[i][j]-(p[i][j])); } } for (ll k = 1; k <= n; k++) for (ll i = 1; i <= n; i++) for (ll j = 1; j <= n; j++) if (dist[i][k]!=LLONG_MAX && dist[k][j]!=LLONG_MAX) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } bool ans = false; for (ll i=1; i<=n;++i) ans = ans || (dist[i][i]<=0); return ans; } int main() { cin >> n >> m >>k; adj.assign(n+1, vector<ll> (n+1, LLONG_MAX)); for (ll i=1; i<=n; ++i) { for(ll j=1;j<=k;++j) cin >> buy[i][j] >> sell[i][j]; } for (ll i=1; i<=n; ++i) for (ll j=1; j<=n; ++j) p[i][j] = 0; for (ll i=1; i<=n; ++i) { for (ll j=1; j<=n; ++j) { for (ll x=1; x<=k;++x) { if (buy[i][x]!=-1 && sell[j][x]!=-1) { p[i][j] = max(p[i][j], -buy[i][x]+sell[j][x]); } } } } for (ll i=0; i<m; ++i) { cin >>x >> y >> z; adj[x][y] = min(adj[x][y], z); } for (ll k = 1; k <= n; k++) for (ll i = 1; i <= n; i++) for (ll j = 1; j <= n; j++) if (adj[i][k]!=LLONG_MAX && adj[k][j]!=LLONG_MAX) { adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]); } ll lo=0, hi = 1e9; while (lo!=hi) { ll mid = (lo+hi+1)/2; if (floydwarshall(mid)) lo = mid; else hi = mid-1; } cout << lo << endl; 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...