Submission #62757

#TimeUsernameProblemLanguageResultExecution timeMemory
62757BenqTravelling Merchant (APIO17_merchant)C++11
100 / 100
142 ms13548 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll,ll> pl; typedef pair<ld,ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<cd> vcd; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; #define FOR(i, a, b) for (int i=a; i<(b); i++) #define F0R(i, a) for (int i=0; i<(a); i++) #define FORd(i,a,b) for (int i = (b)-1; i >= a; i--) #define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--) #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() const int MOD = 1000000007; const ll INF = 1e18; const int MX = 100001; template<int SZ> struct Topo { int N, in[SZ]; vi res, adj[SZ]; void addEdge(int x, int y) { adj[x].pb(y), in[y] ++; } void sort() { queue<int> todo; F0R(i,N) if (in[i] == 0) todo.push(i); while (sz(todo)) { int x = todo.front(); todo.pop(); res.pb(x); for (int i: adj[x]) { in[i] --; if (!in[i]) todo.push(i); } } } }; int N,M,K,B[100][1000],S[100][1000]; int prof[100][100],dist[100][100]; array<ll,100> tmp; vi adj[100]; bool ok(int mid) { F0R(i,N) { adj[i].clear(); tmp[i] = 0; } F0R(i,N) { auto TMP = tmp; F0R(j,N) F0R(k,N) if (j != k && dist[j][k] != MOD) TMP[k] = max(TMP[k],tmp[j]+prof[j][k]-(ll)dist[j][k]*mid); tmp = TMP; } Topo<100> T = Topo<100>(); T.N = N; F0R(j,N) F0R(k,N) if (j != k && dist[j][k] != MOD) { ll d = tmp[j]+prof[j][k]-(ll)dist[j][k]*mid; if (tmp[k] < d) return 1; else if (tmp[k] == d) T.addEdge(j,k); } T.sort(); return sz(T.res) != N; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> N >> M >> K; F0R(i,N) F0R(j,K) cin >> B[i][j] >> S[i][j]; F0R(i,N) F0R(j,N) if (i != j) dist[i][j] = MOD; F0R(i,M) { int V,W,T; cin >> V >> W >> T; V--, W--; dist[V][W] = min(dist[V][W],T); } F0R(k,N) F0R(i,N) F0R(j,N) dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]); F0R(i,N) F0R(j,N) { F0R(k,K) if (B[i][k] != -1 && S[j][k] != -1) prof[i][j] = max(prof[i][j],S[j][k]-B[i][k]); // cout << "AH " << i << " " << j << " " << prof[i][j] << " " << dist[i][j] << "\n"; } ok(6); int lo = 0, hi = MOD; while (lo < hi) { int mid = (lo+hi+1)/2; if (ok(mid)) lo = mid; else hi = mid-1; } cout << lo; } /* Look for: * the exact constraints (multiple sets are too slow for n=10^6 :( ) * special cases (n=1?) * overflow (ll vs int?) * array bounds */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...