제출 #1100541

#제출 시각아이디문제언어결과실행 시간메모리
1100541vjudge1여행하는 상인 (APIO17_merchant)C++17
100 / 100
71 ms4180 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int long long #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (b); i >= (a); i --) #define REP(i, a) for (int i = 0; i < (a); ++i) #define REPD(i, a) for (int i = (a) - 1; i >= 0; --i) #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) constexpr ll LINF = (1ll << 60); constexpr int INF = (1ll << 30); constexpr int Mod = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /* Phu Trong from Nguyen Tat Thanh High School for gifted student */ template <class X, class Y> bool minimize(X &x, const Y &y){ X eps = 1e-9; if (x > y + eps) {x = y; return 1;} return 0; } template <class X, class Y> bool maximize(X &x, const Y &y){ X eps = 1e-9; if (x + eps < y) {x = y; return 1;} return 0; } #define MAX_MARKET 105 #define MAX_CHOICE 1005 int buy[MAX_MARKET][MAX_CHOICE], sell[MAX_MARKET][MAX_CHOICE]; int minDist[MAX_MARKET][MAX_MARKET]; int profit[MAX_MARKET][MAX_MARKET]; int numNode, numEdge, numChoice; namespace SUBTASK_1{ void main(void){ for (int s = 1; s <= numNode; ++s){ for (int u = 1; u <= numNode; ++u){ for (int v = 1; v <= numNode; ++v){ if(minDist[u][v] == minDist[u][s] + minDist[s][v]) maximize(profit[u][v], profit[u][s] + profit[s][v]); } } } int ans = 0; for (int u = 1; u <= numNode; ++u){ for (int v = 1; v <= numNode; ++v) if(u != v){ maximize(ans, (profit[u][v]) / (minDist[u][v] + minDist[v][u])); } } cout << ans; } } namespace SUBTASK_4{ bool SUCCESS(int multi){ vector<vector<int>> totalCost(numNode + 5, vector<int>(numNode + 5, -1e15)); for (int u = 1; u <= numNode; ++u){ for (int v = 1; v <= numNode; ++v) if(u != v and minDist[u][v] < LINF){ totalCost[u][v] = profit[u][v] - 1LL * multi * minDist[u][v]; } } for (int u = 1; u <= numNode; ++u){ for (int v = 1; v <= numNode; ++v) if(u != v){ if(minDist[u][v] < LINF and minDist[v][u] < LINF) maximize(totalCost[u][u], profit[u][u] - 1LL * multi * (minDist[u][v] + minDist[v][u])); } } for (int s = 1; s <= numNode; ++s){ for (int u = 1; u <= numNode; ++u){ for (int v = 1; v <= numNode; ++v){ maximize(totalCost[u][v], totalCost[u][s] + totalCost[s][v]); } } } for (int u = 1; u <= numNode; ++u){ if(totalCost[u][u] >= 0) return true; } return false; } void main(void){ int L = 0, R = 2e9; int ans = 0; while (L <= R){ int M = (L + R) >> 1; if(SUCCESS(M)) L = M + 1, ans = M; else R = M - 1; } cout << ans; } } void process(void){ cin >> numNode >> numEdge >> numChoice; for (int i = 1; i <= numNode; ++i){ for (int j = 1; j <= numChoice; ++j){ cin >> buy[i][j] >> sell[i][j]; } } FOR(u, 1, numNode) FOR(v, 1, numNode) minDist[u][v] = LINF; for (int i = 1; i <= numNode; ++i) minDist[i][i] = 0; for (int i = 1; i <= numEdge; ++i){ int u, v, w; cin >> u >> v >> w; minDist[u][v] = w; } for (int s = 1; s <= numNode; ++s){ for (int u = 1; u <= numNode; ++u){ for (int v = 1; v <= numNode; ++v){ minimize(minDist[u][v], minDist[u][s] + minDist[s][v]); } } } for (int u = 1; u <= numNode; ++u){ for (int v = 1; v <= numNode; ++v) if(minDist[u][v] < LINF){ for (int k = 1; k <= numChoice; ++k) if(sell[v][k] != -1 and buy[u][k] != -1) { maximize(profit[u][v], sell[v][k] - buy[u][k]); } } } // SUBTASK_1 :: main(); SUBTASK_4 :: main(); } signed main(){ #define name "Whisper" cin.tie(nullptr) -> sync_with_stdio(false); //freopen(name".inp", "r", stdin); //freopen(name".out", "w", stdout); process(); return (0 ^ 0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...