Submission #408380

#TimeUsernameProblemLanguageResultExecution timeMemory
408380syl123456Travelling Merchant (APIO17_merchant)C++17
100 / 100
200 ms3316 KiB
#include <bits/stdc++.h> #define all(i) (i).begin(), (i).end() #define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl using namespace std; template<typename T1, typename T2> ostream& operator << (ostream &i, pair<T1, T2> j) { return i << j.first << ' ' << j.second; } template<typename T> ostream& operator << (ostream &i, vector<T> j) { i << '{' << j.size() << ':'; for (T ii : j) i << ' ' << ii; return i << '}'; } typedef long long ll; typedef pair<int, int> pi; const int inf = 1e9 + 1; signed main() { ios::sync_with_stdio(0), cin.tie(0); int n, m, k; cin >> n >> m >> k; vector<vector<int>> b(n, vector<int>(k)), s(n, vector<int>(k)); for (int i = 0; i < n; ++i) for (int j = 0; j < k; ++j) cin >> b[i][j] >> s[i][j]; vector<vector<int>> dis(n, vector<int>(n, inf)); for (int i = 0; i < n; ++i) dis[i][i] = 0; for (int i = 0; i < m; ++i) { int x, y, z; cin >> x >> y >> z; dis[x - 1][y - 1] = z; } for (int ii = 0; ii < n; ++ii) for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) dis[i][j] = min(dis[i][j], dis[i][ii] + dis[ii][j]); vector<vector<int>> v(n, vector<int>(n, 0)); for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) for (int ii = 0; ii < k; ++ii) if (~s[j][ii] && ~b[i][ii]) v[i][j] = max(v[i][j], s[j][ii] - b[i][ii]); int l = 0, r = inf; vector<vector<ll>> tmp(n, vector<ll>(n)); while (l < r - 1) { int mid = l + r >> 1; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) tmp[i][j] = v[i][j] - 1ll * mid * dis[i][j]; bool ok = false; for (int ii = 0; ii < n; ++ii) for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) if (dis[i][ii] < inf && dis[ii][j] < inf) { if (i == j && i != ii && tmp[i][ii] + tmp[ii][j] >= 0) { ok = true; goto out; } tmp[i][j] = max(tmp[i][j], tmp[i][ii] + tmp[ii][j]); } out: if (ok) l = mid; else r = mid; } cout << l; } /* * 0<x<1e9, 0<=ans<=1e9 * y/x >= k ? y-kx >= 0 * * nm all dis * logC * n^2 v[i][j] = max(s[j][ii] - b[i][ii], all ii) - ans * dis[i][j] * n^3 po-cycle * */

Compilation message (stderr)

merchant.cpp: In function 'int main()':
merchant.cpp:40:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |         int mid = l + r >> 1;
      |                   ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...