結果

問題 No.919 You Are A Project Manager
ユーザー kotatsugamekotatsugame
提出日時 2019-10-26 00:13:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,027 bytes
コンパイル時間 1,243 ms
コンパイル使用メモリ 101,828 KB
実行使用メモリ 5,556 KB
最終ジャッジ日時 2023-10-11 12:22:32
合計ジャッジ時間 10,672 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 38 ms
4,352 KB
testcase_07 RE -
testcase_08 AC 270 ms
4,716 KB
testcase_09 AC 179 ms
4,348 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 5 ms
4,348 KB
testcase_13 RE -
testcase_14 AC 17 ms
4,352 KB
testcase_15 AC 120 ms
4,348 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 AC 5 ms
4,352 KB
testcase_40 AC 125 ms
4,352 KB
testcase_41 AC 25 ms
4,352 KB
testcase_42 AC 33 ms
4,348 KB
testcase_43 AC 61 ms
4,348 KB
testcase_44 AC 168 ms
4,368 KB
testcase_45 AC 34 ms
4,352 KB
testcase_46 AC 139 ms
4,352 KB
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 AC 122 ms
4,348 KB
testcase_55 AC 1 ms
4,348 KB
testcase_56 AC 2 ms
4,348 KB
testcase_57 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:39:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   39 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
//1-indexed
#include<vector>
template<typename T>
struct BIT{
	int n;
	vector<T>bit;
	BIT(int n_=0):n(n_),bit(n_+1){}
	T sum(int i)
	{
		T ans=0;
		for(;i>0;i-=i&-i)ans+=bit[i];
		return ans;
	}
	void add(int i,T a)
	{
		if(i==0)return;
		for(;i<=n;i+=i&-i)bit[i]+=a;
	}
	int lower_bound(T k)//k<=sum(ret)
	{
		if(k<=0)return 0;
		int ret=0,i=1;
		while((i<<1)<=n)i<<=1;
		for(;i;i>>=1)
			if(ret+i<=n&&bit[ret+i]<k)k-=bit[ret+=i];
		return ret+1;
	}
};
int N,A[10000];
long L[20000],R[20000];
vector<pair<int,int> >Q;
vector<pair<int,int> >Ai;
map<pair<int,int>,int>mid;
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<N;i++)Ai.push_back(make_pair(A[i],i));
	for(int K=1;K<=N;K++)
	{
		for(int i=0;i+K<=N;i+=K)
		{
			Q.push_back(make_pair(i,i+K));
			Q.push_back(make_pair(N-i-K,N-i));
		}
	}
	for(int i=0;i<Q.size();i++)L[i]=-1e9-1,R[i]=1e9;
	sort(Ai.begin(),Ai.end());
	for(int c=0;c<100;c++)
	{
		vector<pair<long,int> >M;
		for(int i=0;i<Q.size();i++)
		{
			M.push_back(make_pair((L[i]+R[i])/2,i));
		}
		sort(M.begin(),M.end());
		int id=0;
		BIT<int>P(N);
		for(int i=0;i<=Ai.size();i++)
		{
			long T=i<Ai.size()?Ai[i].first:1e18;
			while(id<M.size()&&M[id].first<T)
			{
				int I=M[id].second;
				int l=Q[I].first,r=Q[I].second;
				bool flag=P.sum(r)-P.sum(l)>=(r-l+1)/2;
				if(flag)R[I]=M[id].first;
				else L[I]=M[id].first;
				id++;
			}
			if(i<Ai.size())P.add(Ai[i].second+1,1);
		}
	}
	for(int i=0;i<Q.size();i++)mid[Q[i]]=R[i];
	long ans=0;
	for(int K=1;K<=N;K++)
	{
		int t=(K-1)/2;
		vector<long>L(N/K),R(N/K);
		for(int i=0;i+K<=N;i+=K)
		{
			L[i/K]=mid[make_pair(i,i+K)];
			R[i/K]=mid[make_pair(N-i-K,N-i)];
		}
		for(int i=1;i<N/K;i++)
		{
			L[i]+=L[i-1];
			R[i]+=R[i-1];
		}
		for(int i=1;i<N/K;i++)
		{
			L[i]=max(L[i],L[i-1]);
			R[i]=max(R[i],R[i-1]);
		}
		for(int i=-1;i<N/K;i++)
		{
			int j=N/K-i-2;
			ans=max(ans,((i<0?0L:L[i])+(j<0?0L:R[j]))*K);
		}
	}
	cout<<ans<<endl;
}
0