Submission #60580448
Source Code Expand
#include <bits/stdc++.h> #ifdef LOCAL #include "debug.h" #else #define debug(...) #endif using namespace std; struct Node { int64_t val; Node* l; Node* r; Node(int64_t val_) : val(val_), l(nullptr), r(nullptr) {} }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k; vector<int64_t> a(n); for (int i = 0; i < n; i++) cin >> a[i]; if (k == 1) { sort(a.rbegin(), a.rend()); int64_t ans = 0; for (int i = 0; i < n; i++) { ans += a[i]; cout << ans << " \n"[i == n - 1]; } return 0; } int m = n / k; vector<Node*> b; for (int i = 0; i + k - 1 < n; i++) { int64_t sum = 0; for (int j = i; j <= i + k - 1; j++) sum += a[j]; b.push_back(new Node(sum)); } set<pair<int64_t, Node*>> s; for (int i = 0; i < (int)b.size(); i++) { if (i > 0) b[i]->l = b[i - 1]; if (i < (int)b.size() - 1) b[i]->r = b[i + 1]; s.insert({b[i]->val, b[i]}); } int64_t ans = 0; for (int i = 0; i < m; i++) { debug(i); debug(s); auto it = prev(s.end()); ans += it->first; cout << ans << " \n"[i == m - 1]; auto x = it->second; vector<Node*> t(2 * k - 1, nullptr); t[k - 1] = x; for (int j = k - 1; j >= 0; j--) { if (t[j + 1]) t[j] = t[j + 1]->l; } for (int j = k - 1; j < 2 * k - 1; j++) { if (t[j - 1]) t[j] = t[j - 1]->r; } for (int j = 0; j < 2 * k - 1; j++) { if (t[j]) s.erase({t[j]->val, t[j]}); } vector<Node*> new_nodes; for (int j = 0; j < k - 1; j++) { if (t[j] && t[j + k]) { auto new_node = new Node(t[j]->val + t[j + k]->val - x->val); new_nodes.push_back(new_node); } } if (new_nodes.empty()) { if (t[0] && t[0]->l) t[0]->l->r = nullptr; if (t.back() && t.back()->r) t.back()->r->l = nullptr; } for (int j = 0; j < (int)new_nodes.size(); j++) { if (j > 0) new_nodes[j]->l = new_nodes[j - 1]; if (j < (int)new_nodes.size() - 1) new_nodes[j]->r = new_nodes[j + 1]; s.insert({new_nodes[j]->val, new_nodes[j]}); } if (t[0] && t[0]->l && !new_nodes.empty()) { t[0]->l->r = new_nodes[0]; new_nodes[0]->l = t[0]->l; } if (t.back() && t.back()->r && !new_nodes.empty()) { t.back()->r->l = new_nodes.back(); new_nodes.back()->r = t.back()->r; } } return 0; }
Submission Info
Submission Time | |
---|---|
Task | G - Bar Cover |
User | xindubawukong |
Language | C++ 23 (Clang 16.0.6) |
Score | 0 |
Code Size | 2464 Byte |
Status | WA |
Exec Time | 259 ms |
Memory | 25012 KiB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 625 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_sample_01.txt, 00_sample_02.txt |
All | 00_sample_01.txt, 00_sample_02.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt, 01_test_34.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_01.txt | AC | 1 ms | 3396 KiB |
00_sample_02.txt | AC | 1 ms | 3400 KiB |
01_test_01.txt | AC | 202 ms | 24944 KiB |
01_test_02.txt | WA | 234 ms | 24908 KiB |
01_test_03.txt | WA | 232 ms | 24896 KiB |
01_test_04.txt | WA | 248 ms | 24932 KiB |
01_test_05.txt | AC | 213 ms | 24972 KiB |
01_test_06.txt | WA | 259 ms | 24916 KiB |
01_test_07.txt | WA | 259 ms | 24892 KiB |
01_test_08.txt | WA | 255 ms | 24920 KiB |
01_test_09.txt | AC | 217 ms | 24852 KiB |
01_test_10.txt | WA | 231 ms | 25008 KiB |
01_test_11.txt | WA | 232 ms | 24988 KiB |
01_test_12.txt | WA | 246 ms | 24928 KiB |
01_test_13.txt | AC | 203 ms | 25008 KiB |
01_test_14.txt | WA | 237 ms | 24956 KiB |
01_test_15.txt | WA | 235 ms | 24916 KiB |
01_test_16.txt | AC | 24 ms | 5068 KiB |
01_test_17.txt | AC | 97 ms | 24924 KiB |
01_test_18.txt | AC | 95 ms | 24916 KiB |
01_test_19.txt | AC | 91 ms | 24924 KiB |
01_test_20.txt | AC | 91 ms | 24988 KiB |
01_test_21.txt | AC | 27 ms | 5316 KiB |
01_test_22.txt | AC | 99 ms | 24964 KiB |
01_test_23.txt | AC | 96 ms | 24988 KiB |
01_test_24.txt | AC | 93 ms | 24900 KiB |
01_test_25.txt | AC | 93 ms | 25012 KiB |
01_test_26.txt | WA | 75 ms | 12016 KiB |
01_test_27.txt | WA | 146 ms | 17360 KiB |
01_test_28.txt | WA | 19 ms | 5652 KiB |
01_test_29.txt | WA | 78 ms | 11684 KiB |
01_test_30.txt | WA | 110 ms | 14612 KiB |
01_test_31.txt | AC | 1 ms | 3308 KiB |
01_test_32.txt | AC | 1 ms | 3368 KiB |
01_test_33.txt | AC | 1 ms | 3404 KiB |
01_test_34.txt | WA | 1 ms | 3372 KiB |