Submission #805272

#TimeUsernameProblemLanguageResultExecution timeMemory
805272peijarTravelling Merchant (APIO17_merchant)C++17
21 / 100
77 ms2132 KiB
#include <bits/stdc++.h> #define int long long using namespace std; string to_string(string s) { return s; } template <typename T> string to_string(T v) { bool first = true; string res = "["; for (const auto &x : v) { if (!first) res += ", "; first = false; res += to_string(x); } res += "]"; return res; } void dbg_out() { cout << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << to_string(H); dbg_out(T...); } #ifdef DEBUG #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif const int INF = 1e18; signed main(void) { ios_base::sync_with_stdio(false); cin.tie(0); int nbSommets, nbAretes, nbItems; cin >> nbSommets >> nbAretes >> nbItems; vector<vector<int>> buy(nbSommets, vector<int>(nbItems)); vector<vector<int>> sell(nbSommets, vector<int>(nbItems)); for (int i = 0; i < nbSommets; ++i) for (int j = 0; j < nbItems; ++j) cin >> buy[i][j] >> sell[i][j]; vector<vector<int>> dis(nbSommets, vector<int>(nbSommets, INF)); vector<vector<int>> minLoss(nbSommets, vector<int>(nbSommets)); vector<tuple<int, int, int, int>> edges; for (int iArete = 0; iArete < nbAretes; ++iArete) { int u, v, T; cin >> u >> v >> T; --u, --v; dis[u][v] = T; } for (int k = 0; k < nbSommets; ++k) for (int i = 0; i < nbSommets; ++i) for (int j = 0; j < nbSommets; ++j) dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]); for (int u = 0; u < nbSommets; ++u) for (int item = 0; item < nbItems; ++item) if (buy[u][item] != -1) for (int v = 0; v < nbSommets; ++v) if (sell[v][item] != -1) minLoss[u][v] = min(minLoss[u][v], buy[u][item] - sell[v][item]); vector<vector<int>> dis2(nbSommets); dbg(minLoss); int lo = 0, up = 1e12; while (lo < up) { int x = (lo + up + 1) / 2; for (int u = 0; u < nbSommets; ++u) dis2[u].assign(nbSommets, INF); for (int u = 0; u < nbSommets; ++u) for (int v = 0; v < nbSommets; ++v) if (dis[u][v] < INF) dis2[u][v] = x * dis[u][v] + minLoss[u][v]; for (int k = 0; k < nbSommets; ++k) for (int i = 0; i < nbSommets; ++i) for (int j = 0; j < nbSommets; ++j) if (dis2[i][k] < INF and dis2[k][j] < INF) dis2[i][j] = min(dis2[i][j], dis2[i][k] + dis2[k][j]); bool negCycle = false; for (int u = 0; u < nbSommets; ++u) if (dis2[u][u] <= 0) negCycle = true; if (negCycle) lo = x; else up = x - 1; } cout << lo << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...