結果

問題 No.919 You Are A Project Manager
ユーザー betrue12betrue12
提出日時 2019-10-25 22:56:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 493 ms / 3,000 ms
コード長 2,782 bytes
コンパイル時間 2,063 ms
コンパイル使用メモリ 183,892 KB
実行使用メモリ 395,088 KB
最終ジャッジ日時 2023-09-10 01:04:31
合計ジャッジ時間 9,828 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 108 ms
75,524 KB
testcase_08 AC 13 ms
9,464 KB
testcase_09 AC 9 ms
6,844 KB
testcase_10 AC 18 ms
12,596 KB
testcase_11 AC 16 ms
11,688 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 23 ms
16,996 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 5 ms
5,024 KB
testcase_16 AC 40 ms
28,368 KB
testcase_17 AC 14 ms
4,380 KB
testcase_18 AC 12 ms
4,376 KB
testcase_19 AC 13 ms
4,380 KB
testcase_20 AC 433 ms
333,844 KB
testcase_21 AC 13 ms
4,376 KB
testcase_22 AC 123 ms
86,888 KB
testcase_23 AC 115 ms
83,700 KB
testcase_24 AC 128 ms
92,772 KB
testcase_25 AC 120 ms
86,740 KB
testcase_26 AC 395 ms
321,488 KB
testcase_27 AC 333 ms
257,536 KB
testcase_28 AC 470 ms
379,908 KB
testcase_29 AC 14 ms
4,380 KB
testcase_30 AC 14 ms
4,380 KB
testcase_31 AC 14 ms
4,376 KB
testcase_32 AC 14 ms
4,376 KB
testcase_33 AC 138 ms
101,520 KB
testcase_34 AC 138 ms
101,520 KB
testcase_35 AC 482 ms
395,088 KB
testcase_36 AC 486 ms
395,016 KB
testcase_37 AC 493 ms
394,948 KB
testcase_38 AC 485 ms
395,036 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 6 ms
5,392 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 3 ms
4,380 KB
testcase_43 AC 3 ms
4,376 KB
testcase_44 AC 7 ms
6,224 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 6 ms
5,504 KB
testcase_47 AC 122 ms
87,336 KB
testcase_48 AC 118 ms
85,272 KB
testcase_49 AC 132 ms
95,504 KB
testcase_50 AC 125 ms
86,732 KB
testcase_51 AC 108 ms
74,364 KB
testcase_52 AC 70 ms
49,476 KB
testcase_53 AC 107 ms
74,584 KB
testcase_54 AC 6 ms
5,196 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 1 ms
4,376 KB
testcase_57 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<typename T>
struct BIT {
    int n;
    vector<T> dat;
 
    BIT(int n=0){
        initialize(n);
    }
 
    void initialize(int nin){
        n = nin;
        dat.resize(n, 0);
    }
 
    T sum(int i){
        T s = 0;
        while(i >= 0){
            s += dat[i];
            i = (i & (i+1)) - 1;
        }
        return s;
    }
 
    T sum_between(int i, int j){
        return sum(j) - sum(i-1);
    }
 
    void plus(int i, T x){
        while(i < n){
            dat[i] += x;
            i |= i+1;
        }
    }
};

template<typename T>
struct BIT2D {
    int n;
    vector<BIT<T>> dat;
 
    BIT2D(int nin, int min){
        n = nin;
        dat.resize(n, 0);
        for(int i=0; i<n; i++) dat[i] = BIT<T>(min);
    }
 
    T sum(int i, int js, int jt){
        T s = 0;
        while(i >= 0){
            s += dat[i].sum_between(js, jt);
            i = (i & (i+1)) - 1;
        }
        return s;
    }
 
    T sum_between(int is, int it, int js, int jt){
        return sum(it, js, jt) - sum(is-1, js, jt);
    }
 
    void plus(int i, int j, T x){
        while(i < n){
            dat[i].plus(j, x);
            i |= i+1;
        }
    }

    int lower_bound(int l, int r, T x){
        int ret = -1;
        int k = 1;
        while(2*k <= n) k <<= 1;
        for( ;k>0; k>>=1){
            if(ret+k < n){
                T v = dat[ret+k].sum_between(l, r);
                if(v < x){
                    x -= v;
                    ret += k;
                }
            }
        }
        return ret + 1;
    }
};

void chmax(int64_t& a, int64_t b){
    a = max(a, b);
}

int main(){
    int N, A[10000];
    cin >> N;
    map<int, int> mp;
    for(int i=0; i<N; i++){
        cin >> A[i];
        mp[A[i]] = 0;
    }
    int sz = 0;
    vector<int> cmp;
    for(auto p : mp){
        mp[p.first] = sz++;
        cmp.push_back(p.first);
    }
    
    BIT2D<int> bit(sz, N);
    for(int i=0; i<N; i++) bit.plus(mp[A[i]], i, 1);

    int64_t ans = 0;
    for(int k=1; k<=N; k++){
        int lim = N/k;
        vector<int64_t> ls(lim+1), rs(lim+1);
        for(int i=0; i<lim; i++){
            int s = i*k;
            int t = s+k-1;
            int m = bit.lower_bound(s, t, (k+1)/2);
            ls[i+1] = cmp[m] + ls[i];
        }
        for(int i=0; i<lim; i++){
            int t = N-1-i*k;
            int s = t-k+1;
            int m = bit.lower_bound(s, t, (k+1)/2);
            rs[i+1] = cmp[m] + rs[i];
        }
        for(int i=0; i<lim; i++){
            chmax(ls[i+1], ls[i]);
            chmax(rs[i+1], rs[i]);
        }
        int64_t mx = 0;
        for(int i=0; i<=lim; i++) chmax(mx, ls[i] + rs[lim-i]);
        chmax(ans, mx*k);
    }
    cout << ans << endl;
    return 0;
}
0