結果

問題 No.919 You Are A Project Manager
ユーザー chocoruskchocorusk
提出日時 2019-10-25 22:27:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 500 ms / 3,000 ms
コード長 2,043 bytes
コンパイル時間 1,207 ms
コンパイル使用メモリ 117,248 KB
実行使用メモリ 6,040 KB
最終ジャッジ日時 2023-09-10 00:55:31
合計ジャッジ時間 13,318 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 323 ms
5,804 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 48 ms
4,544 KB
testcase_05 AC 51 ms
4,540 KB
testcase_06 AC 6 ms
4,384 KB
testcase_07 AC 169 ms
4,852 KB
testcase_08 AC 33 ms
4,384 KB
testcase_09 AC 22 ms
4,376 KB
testcase_10 AC 44 ms
4,380 KB
testcase_11 AC 41 ms
4,416 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 55 ms
4,384 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 15 ms
4,380 KB
testcase_16 AC 82 ms
4,612 KB
testcase_17 AC 345 ms
5,872 KB
testcase_18 AC 308 ms
5,976 KB
testcase_19 AC 332 ms
5,856 KB
testcase_20 AC 468 ms
5,620 KB
testcase_21 AC 322 ms
5,852 KB
testcase_22 AC 184 ms
5,156 KB
testcase_23 AC 179 ms
4,972 KB
testcase_24 AC 191 ms
5,064 KB
testcase_25 AC 179 ms
4,928 KB
testcase_26 AC 434 ms
5,708 KB
testcase_27 AC 388 ms
5,572 KB
testcase_28 AC 489 ms
6,008 KB
testcase_29 AC 345 ms
5,928 KB
testcase_30 AC 341 ms
5,880 KB
testcase_31 AC 350 ms
6,040 KB
testcase_32 AC 346 ms
5,888 KB
testcase_33 AC 198 ms
5,060 KB
testcase_34 AC 200 ms
5,020 KB
testcase_35 AC 500 ms
5,924 KB
testcase_36 AC 494 ms
5,820 KB
testcase_37 AC 493 ms
5,980 KB
testcase_38 AC 494 ms
5,912 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 15 ms
4,380 KB
testcase_41 AC 5 ms
4,380 KB
testcase_42 AC 6 ms
4,380 KB
testcase_43 AC 9 ms
4,384 KB
testcase_44 AC 21 ms
4,380 KB
testcase_45 AC 6 ms
4,380 KB
testcase_46 AC 17 ms
4,380 KB
testcase_47 AC 180 ms
5,160 KB
testcase_48 AC 179 ms
4,992 KB
testcase_49 AC 193 ms
5,000 KB
testcase_50 AC 187 ms
4,916 KB
testcase_51 AC 165 ms
4,840 KB
testcase_52 AC 123 ms
4,676 KB
testcase_53 AC 163 ms
4,864 KB
testcase_54 AC 15 ms
4,384 KB
testcase_55 AC 3 ms
4,376 KB
testcase_56 AC 2 ms
4,376 KB
testcase_57 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int sz;
vector<ll> seg[1<<15];

int query(int a, int b, ll x){
	a+=sz, b+=sz;
	int ret=0;
	for(;a<b; a>>=1, b>>=1){
	    if(b&1){
            b--;
            int k=upper_bound(seg[b].begin(), seg[b].end(), x)-seg[b].begin();
            ret+=k;
        }
		if(a&1){
            int k=upper_bound(seg[a].begin(), seg[a].end(), x)-seg[a].begin();
            a++;
            ret+=k;
        }
	}
	return ret;
}
ll a[10010];
ll med(int p, int q){
    int len=q-p;
    if(len==1) return a[p];
    else if(len==2) return min(a[p], a[p+1]);
    ll l=-1e9-7, r=1e9+7;
    while(r-l>1){
        ll mid=(l+r)/2;
        if(query(p, q, mid)>=(len+1)/2) r=mid;
        else l=mid;
    }
    return r;
}
int main()
{
	int n;
    cin>>n;
    for(int i=0; i<n; i++) cin>>a[i];
    sz=1;
	while(sz<n) sz<<=1;
    for(int i=0; i<n; i++) seg[i+sz].push_back(a[i]);
    for(int i=sz-1; i>=1; i--){
        for(auto x:seg[2*i]) seg[i].push_back(x);
        for(auto x:seg[2*i+1]) seg[i].push_back(x);
        sort(seg[i].begin(), seg[i].end());
    }
    ll ans=0;
    for(int k=1; k<=n; k++){
        vector<ll> sl(n/k+1), sr(n/k+1);
        for(int j=0; j<n/k; j++){
            sl[j+1]=sl[j]+med(j*k, (j+1)*k);
        }
        for(int j=0; j<n/k; j++){
            sr[j+1]=sr[j]+med(n-(j+1)*k, n-j*k);
        }
        ll mx=0;
        ans=max(ans, sr[n/k]*k);
        for(int j=1; j<=n/k; j++){
            mx=max(mx, sl[j]);
            ans=max(ans, (mx+sr[n/k-j])*k);        
        }
    }
    cout<<ans<<endl;
    return 0;
}
0