結果

問題 No.919 You Are A Project Manager
ユーザー finefine
提出日時 2019-10-26 01:50:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,290 ms / 3,000 ms
コード長 1,860 bytes
コンパイル時間 1,539 ms
コンパイル使用メモリ 168,924 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-10 01:42:49
合計ジャッジ時間 37,609 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,606 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 31 ms
4,376 KB
testcase_05 AC 35 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 411 ms
4,380 KB
testcase_08 AC 37 ms
4,376 KB
testcase_09 AC 22 ms
4,504 KB
testcase_10 AC 56 ms
4,376 KB
testcase_11 AC 51 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 78 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 11 ms
4,380 KB
testcase_16 AC 140 ms
4,376 KB
testcase_17 AC 429 ms
4,380 KB
testcase_18 AC 424 ms
4,376 KB
testcase_19 AC 1,639 ms
4,380 KB
testcase_20 AC 1,910 ms
4,376 KB
testcase_21 AC 1,618 ms
4,376 KB
testcase_22 AC 495 ms
4,376 KB
testcase_23 AC 459 ms
4,376 KB
testcase_24 AC 528 ms
4,376 KB
testcase_25 AC 481 ms
4,376 KB
testcase_26 AC 1,834 ms
4,380 KB
testcase_27 AC 1,470 ms
4,376 KB
testcase_28 AC 2,092 ms
4,376 KB
testcase_29 AC 427 ms
4,376 KB
testcase_30 AC 425 ms
4,380 KB
testcase_31 AC 425 ms
4,380 KB
testcase_32 AC 835 ms
4,376 KB
testcase_33 AC 581 ms
4,376 KB
testcase_34 AC 549 ms
4,380 KB
testcase_35 AC 2,290 ms
4,380 KB
testcase_36 AC 2,239 ms
4,376 KB
testcase_37 AC 2,222 ms
4,376 KB
testcase_38 AC 2,290 ms
4,384 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 12 ms
4,376 KB
testcase_41 AC 3 ms
4,380 KB
testcase_42 AC 3 ms
4,376 KB
testcase_43 AC 6 ms
4,380 KB
testcase_44 AC 19 ms
4,380 KB
testcase_45 AC 3 ms
4,380 KB
testcase_46 AC 15 ms
4,376 KB
testcase_47 AC 500 ms
4,380 KB
testcase_48 AC 478 ms
4,376 KB
testcase_49 AC 546 ms
4,380 KB
testcase_50 AC 491 ms
4,380 KB
testcase_51 AC 419 ms
4,380 KB
testcase_52 AC 270 ms
4,376 KB
testcase_53 AC 415 ms
4,376 KB
testcase_54 AC 11 ms
4,376 KB
testcase_55 AC 1 ms
4,376 KB
testcase_56 AC 2 ms
4,376 KB
testcase_57 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int partition(vector<ll>& a, int L, int R) {
    ll v = a[R];
    for (int i = L - 1, j = R; ; ) {
        i++;
        j--;
        while (a[i] < v) i++;
        while (a[j] > v) j--;
        if (i >= j) {
            swap(a[i], a[R]);
            return i;
        }
        swap(a[i], a[j]);
    }
}

void quickselect(vector<ll>& a, int L, int R, int k) {
    if (L >= R) return;
    int i = partition(a, L, R);
    if (k < i) quickselect(a, L, i-1, k);
    else quickselect(a, i+1, R, k);
}

ll select_kth(vector<ll>& a, int start, int end, int k) {
    int sz = end - start;
    vector<ll> v(sz);
    for (int i = 0; i < sz; i++) v[i] = a[i + start];
    quickselect(v, 0, sz - 1, k);
    return v[k];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    /*
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j <= n; j++) {
            cerr << i << " " << j << " " << select_kth(a, i, j, (j - i - 1) / 2) << "\n";
        }
    }*/

    ll ans = 0;
    for (int k = 1; k <= n; k++) {
        int max_num = n / k;
        vector<ll> memoL(max_num + 1, 0);
        ll tmp = 0;
        for (int i = 0; i < max_num; i++) {
            tmp += select_kth(a, i * k, (i + 1) * k, (k - 1) / 2) * k;
            memoL[i + 1] = max(memoL[i], tmp);
        }

        vector<ll> memoR(max_num + 1, 0);

        tmp = 0;
        for (int i = 0; i < max_num; i++) {
            tmp += select_kth(a, n - (i + 1) * k, n - i * k, (k - 1) / 2) * k;
            memoR[i + 1] = max(memoR[i], tmp);
        }

        for (int i = 0; i <= max_num; i++) {
            ans = max(ans, memoL[i] + memoR[max_num - i]);
        }
    }
    cout << ans << "\n";
    return 0;
}
0