結果

問題 No.919 You Are A Project Manager
ユーザー kimiyukikimiyuki
提出日時 2019-11-08 05:50:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,418 bytes
コンパイル時間 2,385 ms
コンパイル使用メモリ 208,648 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-13 03:09:12
合計ジャッジ時間 19,830 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,065 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 61 ms
4,352 KB
testcase_05 AC 71 ms
4,352 KB
testcase_06 AC 5 ms
4,348 KB
testcase_07 AC 1,466 ms
4,352 KB
testcase_08 AC 101 ms
4,352 KB
testcase_09 AC 54 ms
4,352 KB
testcase_10 AC 163 ms
4,352 KB
testcase_11 AC 146 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 246 ms
4,352 KB
testcase_14 AC 3 ms
4,356 KB
testcase_15 AC 26 ms
4,348 KB
testcase_16 AC 466 ms
4,352 KB
testcase_17 AC 1,085 ms
4,352 KB
testcase_18 AC 1,084 ms
4,348 KB
testcase_19 AC 2,088 ms
4,348 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 <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) std::begin(x), std::end(x)
#define dump(x) cerr << #x " = " << x << endl
using namespace std;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
template <class T, class U> inline void chmax(T & a, U const & b) { a = max<T>(a, b); }
template <class T, class U> inline void chmin(T & a, U const & b) { a = min<T>(a, b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }
template <typename T> ostream & operator << (ostream & out, vector<T> const & xs) { REP (i, (int)xs.size() - 1) out << xs[i] << ' '; if (not xs.empty()) out << xs.back(); return out; }

int64_t solve(int n, const vector<int> & a) {
    int64_t answer = INT64_MIN;
    REP3 (k, 1, n + 1) {
        // list groups
        vector<int> lower;
        auto b = a;
        for (int l = 0; l + k <= n ; l += k) {
            sort(b.begin() + l, b.begin() + (l + k));
            lower.push_back(b[l + (k - 1) / 2]);
        }
        vector<int> upper;
        b = a;
        for (int r = n; r - k >= 0 ; r -= k) {
            sort(b.begin() + (r - k), b.begin() + r);
            upper.push_back(b[(r - k) + (k - 1) / 2]);
        }

        // make cumulative sums
        vector<int64_t> l(lower.size() + 1);
        int64_t sum_lower = 0;
        REP (i, lower.size()) {
            sum_lower += lower[i];
            l[i + 1] = max(l[i], sum_lower);
        }
        vector<int64_t> r(upper.size() + 1);
        int64_t sum_upper = 0;
        REP (i, upper.size()) {
            sum_upper += upper[i];
            r[i + 1] = max(r[i], sum_upper);
        }

        // make results
        REP (i, l.size()) {
            int j = r.size() - i - 1;
            chmax(answer, k * (l[i] + r[j]));
        }
    }
    return answer;
}

int main() {
    int n; cin >> n;
    vector<int> a(n);
    REP (i, n) {
        cin >> a[i];
    }
    cout << solve(n, a) << endl;
    return 0;
}
0