Submission #538549

#TimeUsernameProblemLanguageResultExecution timeMemory
538549pavementTravelling Merchant (APIO17_merchant)C++17
100 / 100
106 ms4188 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #ifdef _WIN32 #define getchar_unlocked _getchar_nolock #endif #define int long long #define mp make_pair #define mt make_tuple #define pb push_back #define ppb pop_back #define eb emplace_back #define g0(a) get<0>(a) #define g1(a) get<1>(a) #define g2(a) get<2>(a) #define g3(a) get<3>(a) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); using db = double; using ll = long long; using ld = long double; using ii = pair<int, int>; using iii = tuple<int, int, int>; using iiii = tuple<int, int, int, int>; template<class key, class value = null_type, class cmp = less<key> > using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>; int N, M, K, adj[105][105], B[105][1005], S[105][1005], m[105][105], adj2[105][105]; main() { ios::sync_with_stdio(0); cin.tie(0); cin >> N >> M >> K; for (int i = 1; i <= N; i++) for (int j = 1; j <= K; j++) cin >> B[i][j] >> S[i][j]; for (int i = 1; i <= N; i++) for (int j = 1; j <= N; j++) adj[i][j] = 1e16; for (int i = 1, V, W, T; i <= M; i++) { cin >> V >> W >> T; adj[V][W] = min(adj[V][W], T); } 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 <= K; k++) if (S[j][k] != -1 && B[i][k] != -1) m[i][j] = max(m[i][j], S[j][k] - B[i][k]); int lo = 1, hi = 1e9, ans = 0; while (lo <= hi) { int mid = (lo + hi) / 2; bool can = 0; for (int i = 1; i <= N; i++) for (int j = 1; j <= N; j++) adj2[i][j] = mid * min((int)1e16 / mid, adj[i][j]) - m[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({(int)1e16, adj2[i][j], adj2[i][k] + adj2[k][j]}); for (int i = 1; i <= N; i++) if (adj2[i][i] <= 0) can = 1; if (can) ans = mid, lo = mid + 1; else hi = mid - 1; } cout << ans << '\n'; }

Compilation message (stderr)

merchant.cpp:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   31 | 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...