結果
問題 | No.919 You Are A Project Manager |
ユーザー | QCFium |
提出日時 | 2019-11-01 17:38:33 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 367 ms / 3,000 ms |
コード長 | 4,708 bytes |
コンパイル時間 | 2,553 ms |
コンパイル使用メモリ | 196,112 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-27 19:34:44 |
合計ジャッジ時間 | 10,471 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 243 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 22 ms
6,940 KB |
testcase_05 | AC | 24 ms
6,944 KB |
testcase_06 | AC | 3 ms
6,944 KB |
testcase_07 | AC | 97 ms
6,940 KB |
testcase_08 | AC | 15 ms
6,940 KB |
testcase_09 | AC | 10 ms
6,940 KB |
testcase_10 | AC | 21 ms
6,940 KB |
testcase_11 | AC | 19 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 27 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,944 KB |
testcase_15 | AC | 7 ms
6,940 KB |
testcase_16 | AC | 43 ms
6,944 KB |
testcase_17 | AC | 166 ms
6,940 KB |
testcase_18 | AC | 164 ms
6,944 KB |
testcase_19 | AC | 233 ms
6,940 KB |
testcase_20 | AC | 317 ms
6,944 KB |
testcase_21 | AC | 237 ms
6,944 KB |
testcase_22 | AC | 110 ms
6,940 KB |
testcase_23 | AC | 107 ms
6,944 KB |
testcase_24 | AC | 116 ms
6,940 KB |
testcase_25 | AC | 109 ms
6,940 KB |
testcase_26 | AC | 309 ms
6,940 KB |
testcase_27 | AC | 260 ms
6,940 KB |
testcase_28 | AC | 358 ms
6,944 KB |
testcase_29 | AC | 164 ms
6,940 KB |
testcase_30 | AC | 162 ms
6,940 KB |
testcase_31 | AC | 166 ms
6,944 KB |
testcase_32 | AC | 165 ms
6,944 KB |
testcase_33 | AC | 124 ms
6,940 KB |
testcase_34 | AC | 124 ms
6,944 KB |
testcase_35 | AC | 364 ms
6,940 KB |
testcase_36 | AC | 365 ms
6,940 KB |
testcase_37 | AC | 367 ms
6,940 KB |
testcase_38 | AC | 361 ms
6,944 KB |
testcase_39 | AC | 1 ms
6,940 KB |
testcase_40 | AC | 7 ms
6,940 KB |
testcase_41 | AC | 2 ms
6,940 KB |
testcase_42 | AC | 3 ms
6,944 KB |
testcase_43 | AC | 4 ms
6,944 KB |
testcase_44 | AC | 9 ms
6,940 KB |
testcase_45 | AC | 3 ms
6,940 KB |
testcase_46 | AC | 8 ms
6,944 KB |
testcase_47 | AC | 107 ms
6,940 KB |
testcase_48 | AC | 108 ms
6,940 KB |
testcase_49 | AC | 117 ms
6,940 KB |
testcase_50 | AC | 107 ms
6,944 KB |
testcase_51 | AC | 97 ms
6,940 KB |
testcase_52 | AC | 68 ms
6,940 KB |
testcase_53 | AC | 97 ms
6,940 KB |
testcase_54 | AC | 6 ms
6,940 KB |
testcase_55 | AC | 1 ms
6,940 KB |
testcase_56 | AC | 1 ms
6,944 KB |
testcase_57 | AC | 2 ms
6,944 KB |
ソースコード
#include <bits/stdc++.h> int ri() { int n; scanf("%d", &n); return n; } // dummy one struct AVL { struct Node { Node *l; Node *r; int val; int size; int height; Node *fetch() { size = 1 + l->size + r->size; height = 1 + std::max(l->height, r->height); return this; } Node *rotate_l() { Node *new_root = r; r = new_root->l; new_root->l = this; return fetch(), new_root->fetch(); } Node *rotate_r() { Node *new_root = l; l = new_root->r; new_root->r = this; return fetch(), new_root->fetch(); } int height_diff() { return l->height - r->height; } Node *balance() { int dif = height_diff(); if (dif == 2) { if (l->height_diff() < 0) l = l->rotate_l(); return rotate_r(); } else if (dif == -2) { if (r->height_diff() > 0) r = r->rotate_r(); return rotate_l(); } return fetch(); } }; Node nodes[10001]; int head = 0; Node * const NONE = nodes; Node *root = NONE; AVL() { nodes[head++] = {NONE, NONE, 0, 0, 0}; } size_t size_ = 0; private : Node *insert(Node *node, int val) { if (node == NONE) return &(nodes[head++] = {NONE, NONE, val, 1, 1}); if (val < node->val) node->l = insert(node->l, val); else node->r = insert(node->r, val); return node->balance(); } Node *removed_tmp; Node *remove_rightest(Node *node) { if (node->r != NONE) { node->r = remove_rightest(node->r); return node->balance(); } else return (removed_tmp = node)->l; } Node *remove(Node *node, int val) { if (val < node->val) node->l = remove(node->l, val); else if (val > node->val) node->r = remove(node->r, val); else { if (node->l == NONE) return node->r; node->l = remove_rightest(node->l); removed_tmp->l = node->l; removed_tmp->r = node->r; return removed_tmp->balance(); } return node->balance(); } public : int operator [] (int i) { for (Node *cur = root; ; ) { int lsize = cur->l->size; if (i < lsize) cur = cur->l; else if (i > lsize) cur = cur->r, i -= lsize + 1; else return cur->val; } } void insert(int val) { root = insert(root, val); size_++; } void remove(int val) { root = remove(root, val); size_--; } size_t size() { return size_; } }; int main() { int n = ri(); int a[n]; for (int i = 0; i < n; i++) a[i] = ri(); std::vector<int64_t> median_left[n + 1]; std::vector<int64_t> median_right[n + 1]; for (int i = 0; i <= n; i++) { median_left[i].resize(n / (i + 1)); median_right[i].resize(n / (i + 1)); } int sq = sqrt(n); for (int i = 0; i < sq; i++) { { int head = 0; int tail = 0; AVL set; for (int j = 0; i < (int) median_left[j].size(); j++) { // j + 1 while (head < (j + 1) * (i + 1)) set.insert(a[head++]); while (tail < (j + 1) * i) set.remove(a[tail++]); assert(set.size()); median_left[j][i] = set[(set.size() - 1) / 2]; } } { int head = n - 1; int tail = n - 1; AVL set; for (int j = 0; i < (int) median_left[j].size(); j++) { // j + 1 while (head >= n - (j + 1) * (i + 1)) set.insert(a[head--]); while (tail >= n - (j + 1) * i) set.remove(a[tail--]); assert(set.size()); median_right[j][i] = set[(set.size() - 1) / 2]; } } } for (int i = 0; i <= n; i++) { for (int j = sq; j < (int) median_left[i].size(); j++) { std::vector<int> sorted; for (int k = j * (i + 1); k < (j + 1) * (i + 1); k++) sorted.push_back(a[k]); std::sort(sorted.begin(), sorted.end()); median_left[i][j] = sorted[(sorted.size() - 1) / 2]; } for (int j = sq; j < (int) median_right[i].size(); j++) { std::vector<int> sorted; for (int k = n - (j + 1) * (i + 1); k < n - j * (i + 1); k++) sorted.push_back(a[k]); std::sort(sorted.begin(), sorted.end()); median_right[i][j] = sorted[(sorted.size() - 1) / 2]; } } int64_t res = 0; for (int i = 0; i < n; i++) { int max_index_sum = (int) median_left[i].size() - 2; for (int j = 0; j + 1 < (int) median_left[i].size(); j++) median_left[i][j + 1] += median_left[i][j]; for (int j = 0; j + 1 < (int) median_left[i].size(); j++) median_left[i][j + 1] = std::max(median_left[i][j + 1], median_left[i][j]); for (int j = 0; j + 1 < (int) median_right[i].size(); j++) median_right[i][j + 1] += median_right[i][j]; for (int j = 0; j + 1 < (int) median_right[i].size(); j++) median_right[i][j + 1] = std::max(median_right[i][j + 1], median_right[i][j]); int64_t cur = 0; for (int j = 0; j + 1 < (int) median_left[i].size(); j++) cur = std::max(cur, median_left[i][j] + median_right[i][max_index_sum - j]); cur = std::max(cur, median_left[i].back()); cur = std::max(cur, median_right[i].back()); res = std::max(res, cur * (i + 1)); } std::cout << res << std::endl; return 0; }