結果

問題 No.919 You Are A Project Manager
ユーザー machymachy
提出日時 2019-10-25 22:08:18
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,534 bytes
コンパイル時間 877 ms
コンパイル使用メモリ 129,384 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-05-07 19:52:24
合計ジャッジ時間 20,636 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,695 ms
8,960 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 94 ms
5,376 KB
testcase_05 AC 109 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 1,490 ms
5,376 KB
testcase_08 AC 101 ms
5,376 KB
testcase_09 AC 56 ms
5,376 KB
testcase_10 AC 171 ms
5,376 KB
testcase_11 AC 146 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 252 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 27 ms
5,376 KB
testcase_16 AC 461 ms
5,376 KB
testcase_17 AC 1,649 ms
5,376 KB
testcase_18 AC 1,674 ms
5,376 KB
testcase_19 AC 2,625 ms
5,376 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long LL;

LL getMedian(vector<LL>& a, LL begin, LL end){
    sort(a.begin() + begin, a.begin() + end);
    return *(a.begin() + (begin + end - 1) / 2);
}

void build(vector<LL>& a, LL n, LL k, vector<LL>& left, vector<LL>& left_cum){
    for(LL i = 0; (i+1)*k <= n; ++i){
        left[i] = getMedian(a, i*k, (i+1)*k);
    }
    LL cur = 0;
    for(LL i = 0; i < left.size(); ++i){
        cur += left[i];
        left_cum[i+1] = max(cur, left_cum[i]);
    }
}

LL solve(vector<LL> a, LL n, LL k){
    vector<LL> b = a;
    reverse(b.begin(), b.end());
    vector<LL> left(n / k);
    vector<LL> right(n / k);
    vector<LL> left_cum(n / k + 1);
    vector<LL> right_cum(n / k + 1);
    build(a, n, k, left, left_cum);
    build(b, n, k, right, right_cum);
    LL ans = 0;
    for(LL i = 0; i < left_cum.size(); ++i){
        ans = max(ans, left_cum[i] + right_cum[right_cum.size()-1-i]);
    }
    /*
    cerr << "k=" << k << endl;
    for(LL i = 0; i < left_cum.size(); ++i){
        cerr << "left " << left_cum[i] << endl;
    }
    for(LL i = 0; i < left_cum.size(); ++i){
        cerr << "right " << right_cum[i] << endl;
    }
    cerr << "best=" << ans * k << endl;
    */
    return ans * k;
}


int main(){
    LL N;
    cin >> N;
    vector<LL> a(N);
    for(LL i = 0; i < N; ++i){
        cin >> a[i];
    }
    LL ans = 0;
    for(LL k = 1; k <= N; ++k){
        ans = max(ans, solve(a, N, k));
    }
    cout << ans << endl;
}

0