結果
問題 | No.919 You Are A Project Manager |
ユーザー |
|
提出日時 | 2019-10-25 23:23:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,091 bytes |
コンパイル時間 | 874 ms |
コンパイル使用メモリ | 69,660 KB |
実行使用メモリ | 198,528 KB |
最終ジャッジ日時 | 2024-09-13 08:54:58 |
合計ジャッジ時間 | 39,155 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 48 RE * 7 |
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 8 | main() | ^~~~
ソースコード
#include<algorithm> #include<vector> #include<queue> #include<cstdio> using namespace std; int N; vector<int>tb[2][2500]; main() { scanf("%d",&N); vector<int>A(N); for(int i=0;i<N;i++)scanf("%d",&A[i]); long ans=0; for(int K=1;2*K<=N;K++) { vector<long>L(N/K),R(N/K); vector<int>a=A; if(K%2) { for(int i=0;i+K<=N;i+=K)sort(a.begin()+i,a.begin()+i+K); } else { for(int i=0;i+K<=N;i+=K) { int l=0,r=K/2; for(int c=0;c<K;c++) { if(tb[0][K/2][i+l]<tb[0][K/2][i+r]) { a[i+c]=tb[0][K/2][i+l++]; } else { a[i+c]=tb[0][K/2][i+r++]; } } } } for(int i=0;i*K+K<=N;i++) { L[i]=a[i*K+(K-1)/2]; } if(K*4<=N)tb[0][K]=a; a=A; reverse(a.begin(),a.end()); if(K%2) { for(int i=0;i+K<=N;i+=K)sort(a.begin()+i,a.begin()+i+K); } else { for(int i=0;i+K<=N;i+=K) { int l=0,r=K/2; for(int c=0;c<K;c++) { if(tb[1][K/2][i+l]<tb[1][K/2][i+r]) { a[i+c]=tb[1][K/2][i+l++]; } else { a[i+c]=tb[1][K/2][i+r++]; } } } } if(K*4<=N)tb[1][K]=a; for(int i=0;i*K+K<=N;i++) { R[i]=a[i*K+(K-1)/2]; } 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); } } { priority_queue<int>L; priority_queue<int,vector<int>,greater<int> >R; for(int i=0;i<N;i++) { if(L.size()==R.size()) { R.push(A[i]); int t=R.top();R.pop(); L.push(t); } else { L.push(A[i]); int t=L.top();L.pop(); R.push(t); } ans=max(ans,(long)L.top()*(i+1)); } } { priority_queue<int>L; priority_queue<int,vector<int>,greater<int> >R; for(int i=0;i<N;i++) { if(L.size()==R.size()) { R.push(A[N-i-1]); int t=R.top();R.pop(); L.push(t); } else { L.push(A[N-i-1]); int t=L.top();L.pop(); R.push(t); } ans=max(ans,(long)L.top()*(i+1)); } } printf("%ld\n",ans); }