結果

問題 No.919 You Are A Project Manager
ユーザー mamekinmamekin
提出日時 2019-11-06 19:15:54
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,513 bytes
コンパイル時間 1,227 ms
コンパイル使用メモリ 120,532 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-15 00:23:01
合計ジャッジ時間 15,851 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 52 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

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;
    int k = 0;
    while(it1 <= it2){
        if(*it1 < *left || (*it1 == *left && (k++) % 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){
        cerr << len << endl;
        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