結果

問題 No.919 You Are A Project Manager
ユーザー LayCurseLayCurse
提出日時 2019-10-25 23:08:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,924 ms / 3,000 ms
コード長 3,477 bytes
コンパイル時間 2,555 ms
コンパイル使用メモリ 215,500 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2023-12-20 17:45:58
合計ジャッジ時間 33,724 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,490 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 29 ms
6,548 KB
testcase_05 AC 34 ms
6,548 KB
testcase_06 AC 3 ms
6,548 KB
testcase_07 AC 352 ms
6,548 KB
testcase_08 AC 31 ms
6,548 KB
testcase_09 AC 18 ms
6,548 KB
testcase_10 AC 47 ms
6,548 KB
testcase_11 AC 45 ms
6,548 KB
testcase_12 AC 2 ms
6,548 KB
testcase_13 AC 69 ms
6,548 KB
testcase_14 AC 3 ms
6,548 KB
testcase_15 AC 10 ms
6,548 KB
testcase_16 AC 123 ms
6,548 KB
testcase_17 AC 412 ms
6,548 KB
testcase_18 AC 410 ms
6,548 KB
testcase_19 AC 1,491 ms
6,548 KB
testcase_20 AC 1,577 ms
6,548 KB
testcase_21 AC 1,482 ms
6,548 KB
testcase_22 AC 400 ms
6,548 KB
testcase_23 AC 397 ms
6,548 KB
testcase_24 AC 436 ms
6,548 KB
testcase_25 AC 413 ms
6,548 KB
testcase_26 AC 1,569 ms
6,548 KB
testcase_27 AC 1,259 ms
6,548 KB
testcase_28 AC 1,789 ms
6,548 KB
testcase_29 AC 411 ms
6,548 KB
testcase_30 AC 411 ms
6,548 KB
testcase_31 AC 403 ms
6,548 KB
testcase_32 AC 401 ms
6,548 KB
testcase_33 AC 456 ms
6,548 KB
testcase_34 AC 484 ms
6,548 KB
testcase_35 AC 1,904 ms
6,548 KB
testcase_36 AC 1,891 ms
6,548 KB
testcase_37 AC 1,924 ms
6,548 KB
testcase_38 AC 1,839 ms
6,548 KB
testcase_39 AC 2 ms
6,548 KB
testcase_40 AC 10 ms
6,548 KB
testcase_41 AC 3 ms
6,548 KB
testcase_42 AC 4 ms
6,548 KB
testcase_43 AC 5 ms
6,548 KB
testcase_44 AC 17 ms
6,548 KB
testcase_45 AC 4 ms
6,548 KB
testcase_46 AC 12 ms
6,548 KB
testcase_47 AC 407 ms
6,548 KB
testcase_48 AC 395 ms
6,548 KB
testcase_49 AC 463 ms
6,548 KB
testcase_50 AC 411 ms
6,548 KB
testcase_51 AC 358 ms
6,548 KB
testcase_52 AC 222 ms
6,548 KB
testcase_53 AC 344 ms
6,548 KB
testcase_54 AC 10 ms
6,548 KB
testcase_55 AC 2 ms
6,548 KB
testcase_56 AC 2 ms
6,548 KB
testcase_57 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
template<class T> T qselect(int n, int k, T a[]){
  int i;
  int j;
  T v;
  T c[5];
  while(n > 32){
    for(i=(0);i<(5);i++){
      c[i] = a[rand()%n];
    }
    sort(c, c+5);
    v = c[2];
    i = -1;
    j = n;
    for(;;){
      while(a[++i]<v);
      while(a[--j]>v);
      if(i>=j){
        break;
      }
      swap(a[i],a[j]);
    }
    if(k < i){
      n = i;
    }
    else{
      n -= i;
      k -= i;
      a += i;
    }
  }
  sort(a, a+n);
  return a[k];
}
int N;
int A[10000];
int arr[10000];
long long lf[10001];
long long rg[10001];
int main(){
  int K;
  int mx;
  int s;
  long long res = 0;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  int KL2GvlyY = N+1;
  for(K=(1);K<(KL2GvlyY);K++){
    int i;
    mx = N / K;
    for(i=(0);i<(mx);i++){
      int j;
      for(j=(0);j<(K);j++){
        arr[j] = A[i*K+j];
      }
      nth_element(arr, arr+(K-1)/2, arr+K);
      lf[i+1] = lf[i] + (long long) K * arr[(K-1)/2];
    }
    for(i=(0);i<(mx);i++){
      int j;
      for(j=(0);j<(K);j++){
        arr[j] = A[N-1-(i*K+j)];
      }
      nth_element(arr, arr+(K-1)/2, arr+K);
      rg[i+1] = rg[i] + (long long) K * arr[(K-1)/2];
    }
    for(i=(0);i<(mx);i++){
      chmax(lf[i+1], lf[i]);
    }
    for(i=(0);i<(mx);i++){
      chmax(rg[i+1], rg[i]);
    }
    for(i=(0);i<(mx+1);i++){
      chmax(res, lf[i] + rg[mx-i]);
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20191012-1

// --- original code ---
// template<class T>
// T qselect(int n, int k, T a[]){
//   int i, j;
//   T v, c[5];
//   while(n > 32){
//     rep(i,5) c[i] = a[rand()%n];
//     sort(c, c+5);
//     v = c[2];
//     
//     i = -1; j = n;
//     for(;;){
//       while(a[++i]<v);
//       while(a[--j]>v);
//       if(i>=j)break;
//       swap(a[i],a[j]);
//     }
//     if(k < i) n = i;
//     else      n -= i, k -= i, a += i;
//   }
//   sort(a, a+n);
//   return a[k];
// }
// 
// int N, A[1d4];
// int arr[1d4];
// ll lf[10001], rg[10001];
// {
//   int mx, s;
//   ll res = 0;
//   rd(N,A(N));
// //  N = 10000;
// //  rep(i,N) A[i] = rand()%1d9 - rand()%1d9;
// 
//   REP(K,1,N+1){
//     mx = N / K;
//     rep(i,mx){
//       rep(j,K) arr[j] = A[i*K+j];
//       nth_element(arr, arr+(K-1)/2, arr+K);
//       lf[i+1] = lf[i] + (ll) K * arr[(K-1)/2];
//     }
//     rep(i,mx){
//       rep(j,K) arr[j] = A[N-1-(i*K+j)];
//       nth_element(arr, arr+(K-1)/2, arr+K);
//       rg[i+1] = rg[i] + (ll) K * arr[(K-1)/2];
//     }
//     rep(i,mx) lf[i+1] >?= lf[i];
//     rep(i,mx) rg[i+1] >?= rg[i];
//     rep(i,mx+1) res >?= lf[i] + rg[mx-i];
//   }
//   wt(res);
// }
0