結果

問題 No.919 You Are A Project Manager
コンテスト
ユーザー mamekin
提出日時 2019-11-06 20:00:54
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,511 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 837 ms
コンパイル使用メモリ 129,356 KB
最終ジャッジ日時 2026-03-15 21:35:16
合計ジャッジ時間 1,192 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:32:5: error: 'uint32_t' does not name a type
   32 |     uint32_t x, y, z, w;
      |     ^~~~~~~~
main.cpp:27:1: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
   26 | #include <regex>
  +++ |+#include <cstdint>
   27 | using namespace std;
main.cpp:34:22: error: expected ')' before 'seed'
   34 |     Xorshift(uint32_t seed=88675123, int32_t loop=50){
      |             ~        ^~~~~
      |                      )
main.cpp:43:5: error: 'uint32_t' does not name a type
   43 |     uint32_t operator()(){
      |     ^~~~~~~~
main.cpp:43:5: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
main.cpp:48:5: error: 'uint32_t' does not name a type
   48 |     uint32_t operator()(uint32_t size){
      |     ^~~~~~~~
main.cpp:48:5: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
main.cpp: In function 'int quickSelect(std::vector<int>::iterator, std::vector<int>::iterator, int)':
main.cpp:60:34: error: no match for call to '(Xorshift) (int&)'
   60 |     swap(*left, *(left + xorshift(n)));
      |                          ~~~~~~~~^~~

ソースコード

diff #
raw source code

#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 m1 = 0;
    int m2 = 0;
    while(it1 <= it2){
        if(*it1 < *left || (*it1 == *left && m1 < m2)){
            ++ it1;
            ++ m1;
        }
        else{
            swap(*it1, *it2);
            -- it2;
            ++ m2;
        }
    }
    swap(*left, *it2);

    if(index < m1)
        return quickSelect(left, it2, index);
    else if(index == m1)
        return *it2;
    else
        return quickSelect(it1, right, index - m1 - 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