結果

問題 No.919 You Are A Project Manager
ユーザー machymachy
提出日時 2019-10-25 23:48:34
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 2,207 ms / 3,000 ms
コード長 2,280 bytes
コンパイル時間 700 ms
コンパイル使用メモリ 94,312 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 13:21:15
合計ジャッジ時間 30,284 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 977 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 21 ms
4,380 KB
testcase_05 AC 24 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 395 ms
4,380 KB
testcase_08 AC 35 ms
4,380 KB
testcase_09 AC 20 ms
4,380 KB
testcase_10 AC 52 ms
4,380 KB
testcase_11 AC 47 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 80 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 11 ms
4,380 KB
testcase_16 AC 141 ms
4,380 KB
testcase_17 AC 275 ms
4,376 KB
testcase_18 AC 274 ms
4,380 KB
testcase_19 AC 991 ms
4,380 KB
testcase_20 AC 1,990 ms
4,380 KB
testcase_21 AC 1,009 ms
4,380 KB
testcase_22 AC 462 ms
4,380 KB
testcase_23 AC 445 ms
4,376 KB
testcase_24 AC 490 ms
4,380 KB
testcase_25 AC 463 ms
4,380 KB
testcase_26 AC 1,740 ms
4,380 KB
testcase_27 AC 1,377 ms
4,376 KB
testcase_28 AC 2,049 ms
4,376 KB
testcase_29 AC 273 ms
4,376 KB
testcase_30 AC 268 ms
4,380 KB
testcase_31 AC 286 ms
4,380 KB
testcase_32 AC 284 ms
4,380 KB
testcase_33 AC 541 ms
4,380 KB
testcase_34 AC 542 ms
4,380 KB
testcase_35 AC 2,179 ms
4,376 KB
testcase_36 AC 2,114 ms
4,380 KB
testcase_37 AC 2,207 ms
4,380 KB
testcase_38 AC 2,138 ms
4,384 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 11 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 3 ms
4,380 KB
testcase_43 AC 5 ms
4,376 KB
testcase_44 AC 17 ms
4,376 KB
testcase_45 AC 3 ms
4,376 KB
testcase_46 AC 13 ms
4,380 KB
testcase_47 AC 470 ms
4,380 KB
testcase_48 AC 460 ms
4,376 KB
testcase_49 AC 537 ms
4,376 KB
testcase_50 AC 467 ms
4,380 KB
testcase_51 AC 389 ms
4,380 KB
testcase_52 AC 255 ms
4,380 KB
testcase_53 AC 388 ms
4,380 KB
testcase_54 AC 12 ms
4,380 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 2 ms
4,380 KB
testcase_57 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;
typedef long long LL;

LL getPlaced(vector<LL>& a, LL begin, LL end, LL place){
    LL pivot = a[(begin+end)/2];
    LL large = 0;
    LL same = 0;
    for(LL i = begin; i < end-large; ){
        if(a[i] > pivot){
            swap(a[end-1-large], a[i]);
            ++large;
        }else if(a[i] == pivot){
            swap(a[begin+same], a[i]);
            ++same;
            ++i;
        }else{
            ++i;
        }
    }
    //cerr << "debug " << begin << ", " << end << ", " << place << ", " << same << ", " << large << endl;
    LL n = end - begin;
    if(place < n - same - large){
        return getPlaced(a, begin+same, end-large, place);
    }else if(place < n - large){
        return pivot;
    }else{
        return getPlaced(a, end-large, end, place - (n-large));
    }
}

LL getMedian(vector<LL>& a, LL begin, LL end){
    LL n = end - begin;
    return getPlaced(a, begin, end, (n-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