Submission #1093680

#TimeUsernameProblemLanguageResultExecution timeMemory
1093680RiverFlowTravelling Merchant (APIO17_merchant)C++14
12 / 100
1070 ms263652 KiB
#include <bits/stdc++.h> #define nl "\n" #define no "NO" #define yes "YES" #define fi first #define se second #define vec vector #define task "main" #define _mp make_pair #define ii pair<int, int> #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define evoid(val) return void(std::cout << val) #define FOR(i, a, b) for(int i = (a); i <= (b); ++i) #define FOD(i, b, a) for(int i = (b); i >= (a); --i) #define unq(x) sort(all(x)); x.resize(unique(all(x)) - x.begin()) using namespace std; template<typename U, typename V> bool maxi(U &a, V b) { if (a < b) { a = b; return 1; } return 0; } template<typename U, typename V> bool mini(U &a, V b) { if (a > b or a == -1) { a = b; return 1; } return 0; } const int mod = (int)1e9 + 7; void prepare(); void main_code(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } const bool MULTITEST = 0; prepare(); int num_test = 1; if (MULTITEST) cin >> num_test; while (num_test--) { main_code(); } } void prepare() {}; const int N = (int)107; const int K = (int)1007; int n, m, k; int buy[N][K], sell[N][K]; long long d[N][N]; int prof[N][N]; long long dp[N]; const long long INF = -(long long)1e15; bool check(int x) { #define T pair<long long, int> FOR(src, 1, n) { FOR(i, 1, n) if (i != src and d[src][i] != -1 and d[i][src] != -1) { long long l = d[src][i] + d[i][src]; if (prof[src][src] >= 1LL * l * x) return 1; } priority_queue<T> pq; pq.push(_mp(0, src)); FOR(i, 1, n) dp[i] = INF; dp[src] = 0; while (!pq.empty()) { auto j = pq.top(); pq.pop(); if (dp[j.second] > j.first) continue ; int u = j.se; if (u != src and d[u][src] != -1) { if (dp[u] - 1LL * d[u][src] * x + prof[u][src] >= 0) return 1; } FOR(v, 1, n) if (u != v and d[u][v] != -1) { if (maxi(dp[v], dp[u] - 1LL * d[u][v] * x + prof[u][v])) { pq.push(_mp(dp[v], v)); } } } } return 0; } void main_code() { int K; cin >> n >> m >> K; FOR(i, 1, n) { FOR(j, 1, K) { cin >> buy[i][j] >> sell[i][j]; } } memset(d, -1, sizeof d); FOR(i, 1, n) d[i][i] = 0; for(int i = 1; i <= m; ++i) { int u, v, w; cin >> u >> v >> w; d[u][v] = w; } FOR(k, 1, n) FOR(i, 1, n) if (d[i][k] != -1) FOR(j, 1, n) if (d[k][j] != -1) { mini(d[i][j], d[i][k] + d[k][j]); } FOR(i, 1, n) FOR(j, 1, n) if (d[i][j] != -1) { FOR(k, 1, K) if (sell[j][k] != -1 and buy[i][k] != -1) prof[i][j] = max(prof[i][j], sell[j][k] - buy[i][k]); } int lb = 1, rb = (int)1e9, ans = 0; while (lb <= rb) { int mid = (lb + rb) >> 1; if (check(mid)) { ans = mid; lb = mid + 1; } else { rb = mid - 1; } } cout << ans; } /* Let the river flows naturally */

Compilation message (stderr)

merchant.cpp: In function 'int main()':
merchant.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         freopen(task".out", "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...