Submission #657544

#TimeUsernameProblemLanguageResultExecution timeMemory
657544AlexandruabcdeTravelling Merchant (APIO17_merchant)C++14
0 / 100
1065 ms3600 KiB
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair <int, int> PII; constexpr LL INF = 1LL * 1e15; constexpr int NMAX = 102; constexpr int KMAX = 1002; int N, M, K; LL dp[NMAX][KMAX]; int lg[NMAX][KMAX]; bool use[NMAX][KMAX]; LL B[NMAX][NMAX]; LL S[NMAX][NMAX]; vector <PII> G[NMAX]; void Read () { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> M >> K; for (int i = 1; i <= N; ++ i ) for (int j = 1; j <= K; ++ j ) cin >> B[i][j] >> S[i][j]; for (int i = 1; i <= M; ++ i ) { int x, y, t; cin >> x >> y >> t; G[x].push_back({y, t}); } } /* (sell - buy) / time >= r sell - buy - time * r >= 0 buy + time * r - sell <= 0 ? */ bool BFS (int Start, LL r) { for (int i = 1; i <= N; ++ i ) for (int j = 0; j <= K; ++ j ) { dp[i][j] = INF; lg[i][j] = 0; use[i][j] = false; } dp[Start][0] = 0; use[Start][0] = true; lg[Start][0] = 1; queue <PII> Q; Q.push({Start, 0}); while (!Q.empty()) { int i = Q.front().first; int j = Q.front().second; Q.pop(); use[i][j] = false; ///dau sell if (j != 0) { if (dp[i][0] > dp[i][j] - S[i][j]) { dp[i][0] = dp[i][j] + S[i][j]; lg[i][0] = lg[i][j]; if (!use[i][0]) { Q.push({i, 0}); use[i][0] = true; } } } ///buy if (j == 0) { for (int k = 1; k <= K; ++ k ) { if (dp[i][k] > dp[i][0] + B[i][k]) { dp[i][k] = dp[i][0] + B[i][k]; lg[i][k] = lg[i][j]; if (!use[i][k]) { Q.push({i, k}); use[i][k] = true; } } } } for (auto it : G[i]) { int to = it.first; LL cost_scad = r * it.second; if (dp[to][j] > dp[i][j] + cost_scad) { dp[to][j] = dp[i][j] + cost_scad; lg[to][j] = lg[i][j] + 1; if (lg[to][j] > N) return true; if (!use[to][j]) { use[to][j] = true; Q.push({to, j}); } } } } return false; } void Solve () { LL st = 1, dr = 100, ans = 0; while (st <= dr) { LL mij = (st + dr) / 2; if (BFS(1, mij)) { st = mij + 1; ans = mij; } else dr = mij - 1; } cout << ans << '\n'; } int main () { Read(); Solve(); return 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...