結果

問題 No.919 You Are A Project Manager
ユーザー tsutajtsutaj
提出日時 2019-10-26 13:32:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,764 ms / 3,000 ms
コード長 2,364 bytes
コンパイル時間 1,031 ms
コンパイル使用メモリ 110,448 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 07:47:41
合計ジャッジ時間 55,744 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,142 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 142 ms
4,352 KB
testcase_05 AC 166 ms
4,348 KB
testcase_06 AC 4 ms
4,352 KB
testcase_07 AC 501 ms
4,348 KB
testcase_08 AC 41 ms
4,348 KB
testcase_09 AC 23 ms
4,348 KB
testcase_10 AC 64 ms
4,348 KB
testcase_11 AC 57 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 93 ms
4,348 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 12 ms
4,348 KB
testcase_16 AC 170 ms
4,348 KB
testcase_17 AC 2,139 ms
4,348 KB
testcase_18 AC 2,134 ms
4,348 KB
testcase_19 AC 2,144 ms
4,348 KB
testcase_20 AC 2,324 ms
4,352 KB
testcase_21 AC 2,138 ms
4,348 KB
testcase_22 AC 580 ms
4,352 KB
testcase_23 AC 555 ms
4,348 KB
testcase_24 AC 622 ms
4,352 KB
testcase_25 AC 579 ms
4,348 KB
testcase_26 AC 2,236 ms
4,352 KB
testcase_27 AC 1,787 ms
4,348 KB
testcase_28 AC 2,647 ms
4,352 KB
testcase_29 AC 2,134 ms
4,352 KB
testcase_30 AC 2,149 ms
4,352 KB
testcase_31 AC 2,138 ms
4,352 KB
testcase_32 AC 2,135 ms
4,352 KB
testcase_33 AC 681 ms
4,348 KB
testcase_34 AC 683 ms
4,348 KB
testcase_35 AC 2,764 ms
4,348 KB
testcase_36 AC 2,756 ms
4,348 KB
testcase_37 AC 2,759 ms
4,352 KB
testcase_38 AC 2,763 ms
4,348 KB
testcase_39 AC 2 ms
4,352 KB
testcase_40 AC 13 ms
4,348 KB
testcase_41 AC 2 ms
4,352 KB
testcase_42 AC 3 ms
4,348 KB
testcase_43 AC 6 ms
4,348 KB
testcase_44 AC 20 ms
4,348 KB
testcase_45 AC 3 ms
4,352 KB
testcase_46 AC 15 ms
4,348 KB
testcase_47 AC 583 ms
4,352 KB
testcase_48 AC 569 ms
4,348 KB
testcase_49 AC 638 ms
4,352 KB
testcase_50 AC 576 ms
4,352 KB
testcase_51 AC 491 ms
4,352 KB
testcase_52 AC 318 ms
4,352 KB
testcase_53 AC 495 ms
4,348 KB
testcase_54 AC 13 ms
4,348 KB
testcase_55 AC 1 ms
4,352 KB
testcase_56 AC 2 ms
4,352 KB
testcase_57 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    vector< pair<ll, ll> > A(N);
    for(int i=0; i<N; i++) {
        ll v; cin >> v;
        A[i] = make_pair(v, i);
    }

    sort(A.begin(), A.end());
    vector<ll> L(N), R(N), CL(N), CR(N);

    ll ans = 0;
    for(int K=1; K<=N; K++) {
        int B = N / K;
        fill(L.begin(), L.begin() + B, 0);
        fill(R.begin(), R.begin() + B, 0);

        int half = (K + 1) / 2;
        for(int i=0; i<N; i++) {
            int b = A[i].second / K;
            if(b >= B) continue;
            if(++L[b] == half) CL[b] = A[i].first;
        }
        for(int i=0; i<N; i++) {
            int b = (N - 1 - A[i].second) / K;
            if(b >= B) continue;
            if(++R[b] == half) CR[b] = A[i].first;
        }

        for(int i=1; i<B; i++) {
            CL[i] += CL[i-1];
            CR[i] += CR[i-1];
        }
        for(int i=1; i<B; i++) {
            chmax(CL[i], CL[i-1]);
            chmax(CR[i], CR[i-1]);
        }

        chmax(ans, K * max(CL[B-1], CR[B-1]));

        // l: [ K*l, K*(l+1) )
        // r: (N-1-K*(r+1) , N-1-K*r]
        // bl - ar は -1 以上であれば OK
        int l, r = B-1;
        for(l=0; l<B; l++) {
            int al = K*l, ar = K*(l+1);
            int bl = N-1-K*(r+1), br = N-1-K*r;
            while(r >= 0 and bl - ar < -1) r--, bl += K, br += K;
            if(r >= 0) chmax(ans, K * (CL[l] + CR[r]));
        }
    }
    cout << ans << endl;
    return 0;
}
0