結果
問題 |
No.919 You Are A Project Manager
|
ユーザー |
|
提出日時 | 2019-10-25 23:22:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,074 bytes |
コンパイル時間 | 1,129 ms |
コンパイル使用メモリ | 89,636 KB |
実行使用メモリ | 199,424 KB |
最終ジャッジ日時 | 2024-06-27 17:31:16 |
合計ジャッジ時間 | 39,233 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 54 WA * 1 |
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 8 | main() | ^~~~
ソースコード
#include<iostream> #include<algorithm> #include<vector> #include<queue> using namespace std; int N; vector<int>tb[2][10000]; main() { cin>>N; vector<int>A(N); for(int i=0;i<N;i++)cin>>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)); } } cout<<ans<<endl; }