Submission #1082284

#TimeUsernameProblemLanguageResultExecution timeMemory
1082284vuavisaoCloud Computing (CEOI18_clo)C++14
100 / 100
1551 ms2204 KiB
#include <bits/stdc++.h> using namespace std; const int N = (int) 2e3 + 10; const long long INF = (long long) 1e18; struct computer { int core, circuit, cost; computer() : core(0), circuit(0), cost(0) {}; bool operator<(const computer& other) const { if (abs(this->circuit) != abs(other.circuit)) return abs(this->circuit) > abs(other.circuit); // drecreasing order if (1ll * this->circuit * other.circuit < 0) return this->circuit > 0; // priority computer than query if(this->core != other.core) return this->core > other.core; return this->cost > other.cost; } }; int n, q; computer c[N]; computer qq[N]; namespace sub4 { bool check() { for (int i = 1; i <= n; ++ i) { if (c[i].circuit != 1) return false; } for (int i = 1; i <= q; ++ i) { if (qq[i].circuit != 1) return false; } return true; } long long dpNeed[2][N * 60]; long long dpProfit[2][N * 60]; void solve() { int maxCoreNeed = n * 50; for (int i = 0; i < 2; ++ i) { for (int s = 0; s <= maxCoreNeed; ++ s) { dpNeed[i][s] = INF; } } dpNeed[0][0] = 0; for (int i = 0, x = 0, y = 1; i < n; ++ i, x = !x, y = !y) { int cntCore = c[i + 1].core, cost = c[i + 1].cost; for (int s = maxCoreNeed; s >= 0; -- s) { int nxtS = min(maxCoreNeed, s + cntCore); dpNeed[y][nxtS] = min(dpNeed[y][nxtS], dpNeed[x][s] + cost); dpNeed[y][s] = min(dpNeed[y][s], dpNeed[x][s]); if (s < maxCoreNeed) { dpNeed[y][s] = min(dpNeed[y][s], dpNeed[y][s + 1]); } dpNeed[x][s] = INF; } } int maxCoreProfit = q * 50; for (int i = 0; i < 2; ++ i) { for (int s = 0; s <= maxCoreProfit; ++ s) { dpProfit[i][s] = -INF; } } dpProfit[0][0] = 0; for (int i = 0, x = 0, y = 1; i < q; ++ i, x = !x, y = !y) { int cntCore = qq[i + 1].core, cost = qq[i + 1].cost; for (int s = maxCoreProfit; s >= 0; -- s) { dpProfit[y][s] = max(dpProfit[y][s], dpProfit[x][s]); int nxtS = s + cntCore; if (nxtS <= maxCoreProfit) { dpProfit[y][nxtS] = max(dpProfit[y][nxtS], dpProfit[x][s] + cost); } dpProfit[x][s] = -INF; } } int x = n & 1, y = q & 1; long long res = 0; for (int s = 0; s <= min(maxCoreNeed, maxCoreProfit); ++ s) { res = max(res, dpProfit[y][s] - dpNeed[x][s]); } cout << res; } } namespace sub6 { computer general[N << 1]; long long dp[2][N * 60]; void solve() { for (int i = 1; i <= n; ++ i) { general[i] = c[i]; general[i].cost = -general[i].cost; } for (int i = 1; i <= q; ++ i) { general[i + n] = qq[i]; general[i + n].circuit = -general[i + n].circuit; general[i + n].core = -general[i + n].core; } int maxCore = n * 50; for (int i = 0; i < 2; ++ i) { for (int s = 0; s <= maxCore; ++ s) { dp[i][s] = -INF; } } sort(general + 1, general + 1 + n + q); dp[0][0] = 0; for (int i = 0, x = 0, y = 1; i < n + q; ++ i, x = !x, y = !y) { int cntCore = general[i + 1].core, cost = general[i + 1].cost; for (int s = maxCore; s >= 0; -- s) { int nxtS = min(maxCore, s + cntCore); if (nxtS >= 0) { dp[y][nxtS] = max(dp[y][nxtS], dp[x][s] + cost); } dp[y][s] = max(dp[y][s], dp[x][s]); if (s < maxCore) { dp[y][s] = max(dp[y][s], dp[y][s + 1]); } dp[x][s] = -INF; } } int x = (n + q) & 1; long long res = 0; for (int s = 0; s <= maxCore; ++ s) { res = max(res, dp[x][s]); } cout << res; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n; for (int i = 1; i <= n; ++ i) cin >> c[i].core >> c[i].circuit >> c[i].cost; cin >> q; for (int i = 1; i <= q; ++ i) cin >> qq[i].core >> qq[i].circuit >> qq[i].cost; // if (sub4::check()) { // sub4::solve(); // return 0; // } sub6::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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...