Submission #1082277

#TimeUsernameProblemLanguageResultExecution timeMemory
1082277vuavisaoCloud Computing (CEOI18_clo)C++14
18 / 100
786 ms3668 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3", "unroll-loops") using namespace std; using ll = long long; const int N = 2'000 + 10; const ll INF = 1'000'000'000'000'000'000; struct computer { int core, circuit, cost; computer() : core(0), circuit(0), cost(0) {}; }; 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; } ll dpNeed[2][N * 60]; ll 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; ll res = 0; for (int s = 0; s <= min(maxCoreNeed, maxCoreProfit); ++ s) { // cerr << dpProfit[y][s] << ' ' << dpNeed[x][s] << '\n'; res = max(res, dpProfit[y][s] - dpNeed[x][s]); } cout << res; } } int32_t main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::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; } assert(false); return (0 ^ 0); } /// Code by vuavisao
#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...