結果

問題 No.919 You Are A Project Manager
ユーザー polyomino_24polyomino_24
提出日時 2019-10-26 19:24:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,395 bytes
コンパイル時間 1,522 ms
コンパイル使用メモリ 135,640 KB
実行使用メモリ 12,304 KB
最終ジャッジ日時 2023-10-12 17:46:55
合計ジャッジ時間 11,942 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
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 <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int Find_median(vector<int>a){
    assert(a.size()<=5);
    sort(a.begin(),a.end());
    return a[a.size()/2];
}
//T(n) = T(n/5) + T() + O(n)
int kth_smallest(const vector<int>&a, int l, int r, int k){
    if(k <= 0 or r - l < k)return INT_MAX;
    vector<int>med;
    for(int i = l; i < r;){
        vector<int>temp;
        for(int j = 0; j < 5; j++){
            if(i < r) temp.push_back(a[i++]);
        }
        med.push_back(Find_median(temp));
    }
    int medofmed = (med.size() == 1) ? med[0] :  kth_smallest(med, 0, (int) med.size(), (int) med.size() / 2);
    vector<int> b,c,d;
    for (int i = l; i < r; i++){
        if(a[i] < medofmed){
            b.push_back(a[i]);
        }else if(a[i] == medofmed){
            c.push_back(a[i]);
        }else{
            d.push_back(a[i]);
        }
    }
    if(b.size() >= k){
        return kth_smallest(b, 0, (int) b.size(), k);
    }else if(b.size() + c.size() >= k){
        return medofmed;
    }else{
        return kth_smallest(d, 0, (int) d.size(), k - (int) b.size() - (int) c.size());
    }
    return INT_MAX;
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    const int offset = 1e9;
    vector<int>a(n);
    rep(i,n)cin >> a[i];
    rep(i,n)a[i] += offset;
    ll ans = -(1LL<<60);
    for(int k = 1; k <= n; k++){
        ll sum = 0;
        const int pos = (k - 1)/ 2 + 1;
        show(pos);
        vector<ll> dp[2];
        for(int i = 0; i + k <= n; i+= k){
            dp[0].push_back((ll)k * (kth_smallest(a,i, i + k, pos) - offset));
        }
        for(int i = n; i - k >= 0; i-= k){
            dp[1].push_back((ll)k * (kth_smallest(a,i - k, i, pos) - offset));
        }
        show(dp[0],dp[1]);
        const int sz = (int) dp[0].size();
        rep(i,2){
            sum = max(sum,dp[i][0]);
            rep(j,sz-1){
                dp[i][j+1] += dp[i][j];
                sum = max(sum, dp[i][j+1]);
            }
        }
        vector<ll> rui(sz);
        rep(i,sz){
            if(i==0)rui[i] = dp[0][0];
            else rui[i] = max(rui[i-1], dp[0][i]);
        }
        rep(i,sz-1){
            sum = max(sum, rui[i] + dp[1][sz - 2 -i]);
        }
        show(k, sz, sum);
        ans = max(ans, sum);
    }
    cout << ans << endl;
}
0