結果

問題 No.919 You Are A Project Manager
ユーザー りあんりあん
提出日時 2019-10-25 22:05:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,054 bytes
コンパイル時間 2,271 ms
コンパイル使用メモリ 211,756 KB
実行使用メモリ 199,520 KB
最終ジャッジ日時 2023-10-11 04:37:04
合計ジャッジ時間 57,436 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,823 ms
199,280 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 49 ms
16,284 KB
testcase_05 AC 57 ms
18,504 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 619 ms
39,616 KB
testcase_08 AC 48 ms
6,324 KB
testcase_09 AC 27 ms
5,028 KB
testcase_10 AC 75 ms
8,068 KB
testcase_11 AC 69 ms
7,608 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 111 ms
10,228 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 14 ms
4,348 KB
testcase_16 AC 205 ms
15,908 KB
testcase_17 AC 1,392 ms
199,000 KB
testcase_18 AC 1,391 ms
199,156 KB
testcase_19 AC 1,831 ms
199,248 KB
testcase_20 TLE -
testcase_21 AC 1,813 ms
199,196 KB
testcase_22 AC 713 ms
45,348 KB
testcase_23 AC 680 ms
43,600 KB
testcase_24 AC 767 ms
48,296 KB
testcase_25 AC 717 ms
45,240 KB
testcase_26 AC 2,938 ms
162,480 KB
testcase_27 AC 2,311 ms
130,512 KB
testcase_28 TLE -
testcase_29 AC 1,423 ms
199,068 KB
testcase_30 AC 1,387 ms
199,204 KB
testcase_31 AC 1,182 ms
199,052 KB
testcase_32 AC 1,434 ms
198,972 KB
testcase_33 AC 843 ms
52,616 KB
testcase_34 AC 839 ms
52,516 KB
testcase_35 TLE -
testcase_36 TLE -
testcase_37 TLE -
testcase_38 TLE -
testcase_39 AC 2 ms
4,352 KB
testcase_40 AC 14 ms
4,352 KB
testcase_41 AC 3 ms
4,348 KB
testcase_42 AC 4 ms
4,352 KB
testcase_43 AC 6 ms
4,348 KB
testcase_44 AC 24 ms
4,924 KB
testcase_45 AC 3 ms
4,348 KB
testcase_46 AC 18 ms
4,600 KB
testcase_47 AC 718 ms
45,628 KB
testcase_48 AC 697 ms
44,680 KB
testcase_49 AC 792 ms
49,556 KB
testcase_50 AC 712 ms
45,104 KB
testcase_51 AC 604 ms
38,976 KB
testcase_52 AC 388 ms
26,464 KB
testcase_53 AC 606 ms
39,048 KB
testcase_54 AC 15 ms
4,476 KB
testcase_55 AC 2 ms
4,356 KB
testcase_56 AC 2 ms
4,352 KB
testcase_57 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int M = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<vector<int>> mid(n + 1);
    for (int i = 1; i <= n; ++i) {
        mid[i] = vector<int>(i);
    }
    for (int i = 0; i < n; ++i) {
        priority_queue<int> lq;
        priority_queue<int, vector<int>, greater<int>> uq;
        mid[i + 1][i] = a[i];
        if (i == n - 1) continue;

        mid[i + 2][i] = min(a[i], a[i + 1]);
        lq.push(min(a[i], a[i + 1]));
        uq.push(max(a[i], a[i + 1]));
        for (int j = i + 2; j < n; ++j) {
            if (lq.top() <= a[j] && a[j] <= uq.top()) {
                if (lq.size() == uq.size())
                    lq.push(a[j]);
                else
                    uq.push(a[j]);
            }
            else if (lq.top() > a[j]) {
                lq.push(a[j]);
                while (lq.size() > uq.size() + 1) {
                    uq.push(lq.top());
                    lq.pop();
                }
            }
            else {
                uq.push(a[j]);
                while (uq.size() > lq.size()) {
                    lq.push(uq.top());
                    uq.pop();
                }
            }
            mid[j + 1][i] = lq.top();
        }
    }
    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
        vector<long long> sl(n / i + 1), sr(n / i + 1);
        vector<long long> ml(n / i + 1), mr(n / i + 1);
        for (int j = 0; j < n / i; ++j) {
            sl[j + 1] = sl[j] + mid[(j + 1) * i][j * i] * (long long)i;
            ml[j + 1] = max(ml[j], sl[j + 1]);
        }
        for (int j = 0; j < n / i; ++j) {
            sr[j + 1] = sr[j] + mid[n - j * i][n - (j + 1) * i] * (long long)i;
            mr[j + 1] = max(mr[j], sr[j + 1]);
        }
        for (int j = 0; j < n / i; ++j) {
            ans = max(ans, ml[j] + mr[n / i - j]);
        }
    }
    cout << ans << '\n';

    return 0;
}
0