結果

問題 No.919 You Are A Project Manager
ユーザー mamekinmamekin
提出日時 2019-11-06 19:09:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,472 bytes
コンパイル時間 1,116 ms
コンパイル使用メモリ 119,804 KB
実行使用メモリ 12,232 KB
最終ジャッジ日時 2023-10-13 02:39:03
合計ジャッジ時間 9,607 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

class Xorshift
{
private:
    uint32_t x, y, z, w;
public:
    Xorshift(uint32_t seed=88675123, int32_t loop=50){
        x = 123456789;
        y = 362436069;
        z = 521288629;
        w = seed;
        while(--loop >= 0){
            (*this)();
        }
    }
    uint32_t operator()(){
        uint32_t t=(x^(x<<11));
        x=y; y=z; z=w;
        return w=(w^(w>>19))^(t^(t>>8));
    }
    uint32_t operator()(uint32_t size){
        return (*this)() % size;
    }
};
Xorshift xorshift;

int quickSelect(vector<int>::iterator left, vector<int>::iterator right, int index)
{
    int n = right - left;
    if(n == 1)
        return *left;

    swap(*left, *(left + xorshift(n)));
    auto it1 = left + 1;
    auto it2 = right - 1;
    while(it1 <= it2){
        if(*it1 <= *left || (*it1 == *left && xorshift(2) == 0)){
            ++ it1;
        }
        else{
            swap(*it1, *it2);
            -- it2;
        }
    }
    swap(*left, *it2);

    int m = it2 - left;
    if(index < m)
        return quickSelect(left, it2, index);
    else if(index == m)
        return *it2;
    else
        return quickSelect(it1, right, index - m - 1);
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];

    long long ans = 0;
    for(int len=1; len<=n; ++len){
        int m = n / len;
        vector<int> a1 = a;
        vector<int> a2 = a;
        vector<long long> v1(m+1), v2(m+1);
        for(int i=0; i<m; ++i){
            v1[i+1] = v1[i] + quickSelect(a1.begin() + len * i, a1.begin() + len * (i + 1), (len - 1) / 2);
            v2[i+1] = v2[i] + quickSelect(a2.end() - len * (i + 1), a2.end() - len * i, (len - 1) / 2);
        }
        for(int i=0; i<m; ++i){
            v1[i+1] = max(v1[i+1], v1[i]);
            v2[i+1] = max(v2[i+1], v2[i]);
        }
        for(int i=0; i<=m; ++i)
            ans = max(ans, (v1[i] + v2[m-i]) * len);
    }
    cout << ans << endl;

    return 0;
}
0