제출 #1082280

#제출 시각아이디문제언어결과실행 시간메모리
1082280vuavisaoCloud Computing (CEOI18_clo)C++14
0 / 100
2 ms860 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) {}; bool operator<(const computer& other) const { if (abs(this->circuit) != other.circuit) return abs(this->circuit) > 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; } 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; } } namespace sub6 { computer general[N << 1]; ll 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; ll res = 0; for (int s = 0; s <= maxCore; ++ s) { // cerr << dp[x][s] << '\n'; res = max(res, dp[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; // } sub6::solve(); 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...