Submission #584309

#TimeUsernameProblemLanguageResultExecution timeMemory
584309thezomb1eTravelling Merchant (APIO17_merchant)C++17
100 / 100
111 ms4180 KiB
//thatsramen #include <bits/stdc++.h> #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define eb emplace_back #define pb push_back #define ft first #define sd second #define pi pair<int, int> #define pll pair<ll, ll> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define dbg(...) dbg_out(__VA_ARGS__) using ll = long long; using ld = long double; using namespace std; using namespace __gnu_pbds; //Constants const ll INF = 5 * 1e18; const int IINF = 2 * 1e9; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const ld PI = 3.14159265359; //Templates template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) {return os << '(' << p.first << ", " << p.second << ')';} template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '['; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << ']';} void dbg_out() {cerr << endl;} template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << H << ' '; dbg_out(T...); } template<typename T> void mins(T& x, T y) {x = min(x, y);} template<typename T> void maxs(T& x, T y) {x = max(x, y);} template<typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; //order_of_key(k): number of elements strictly less than k //find_by_order(k): k-th element in the set void setPrec() {cout << fixed << setprecision(15);} void unsyncIO() {cin.tie(0)->sync_with_stdio(0);} void setIn(string s) {freopen(s.c_str(), "r", stdin);} void setOut(string s) {freopen(s.c_str(), "w", stdout);} void setIO(string s = "") { unsyncIO(); setPrec(); if(s.size()) setIn(s + ".in"), setOut(s + ".out"); } // #define TEST_CASES const ll MAX = 2ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000; void solve() { int n, m, k; cin >> n >> m >> k; vector<vector<pll>> cost(n, vector<pll> (k)); for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { cin >> cost[i][j].ft >> cost[i][j].sd; } } vector<vector<ll>> dist(n, vector<ll> (n, MAX)); for (int i = 0; i < m; i++) { int u, v; ll t; cin >> u >> v >> t; u--; v--; dist[u][v] = t; } auto floyd = [&](vector<vector<ll>> &adj) { for (int z = 0; z < n; z++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { mins(adj[i][j], adj[i][z] + adj[z][j]); } } } }; floyd(dist); vector<vector<ll>> prof(n, vector<ll> (n, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int z = 0; z < k; z++) { if (cost[i][z].ft == -1) continue; if (cost[j][z].sd == -1) continue; maxs(prof[i][j], cost[j][z].sd - cost[i][z].ft); } } } auto ok = [&](ll rat) -> bool { vector<vector<ll>> adj(n, vector<ll> (n, MAX)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { adj[i][j] = min(dist[i][j], MAX / rat) * rat - prof[i][j]; } } floyd(adj); for (int i = 0; i < n; i++) { if (adj[i][i] <= 0) return true; } return false; }; ll ans = 0; ll lo = 1, hi = 1ll * 1000 * 1000 * 1000 * 1000; while (lo <= hi) { ll mi = lo + (hi - lo) / 2; if (ok(mi)) { ans = mi; lo = mi + 1; } else { hi = mi - 1; } } cout << ans; } int main() { setIO(); int tt = 1; #ifdef TEST_CASES cin >> tt; #endif while (tt--) solve(); return 0; }

Compilation message (stderr)

merchant.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    5 | #pragma GCC optimization ("O3")
      | 
merchant.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    6 | #pragma GCC optimization ("unroll-loops")
      | 
merchant.cpp: In function 'void setIn(std::string)':
merchant.cpp:48:30: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 | void setIn(string s) {freopen(s.c_str(), "r", stdin);}
      |                       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp: In function 'void setOut(std::string)':
merchant.cpp:49:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 | void setOut(string s) {freopen(s.c_str(), "w", stdout);}
      |                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...