結果

問題 No.919 You Are A Project Manager
ユーザー LayCurseLayCurse
提出日時 2019-11-02 11:38:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,862 ms / 3,000 ms
コード長 2,472 bytes
コンパイル時間 2,715 ms
コンパイル使用メモリ 211,492 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-10 03:53:46
合計ジャッジ時間 32,278 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,471 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 30 ms
4,380 KB
testcase_05 AC 34 ms
4,380 KB
testcase_06 AC 3 ms
4,384 KB
testcase_07 AC 342 ms
4,380 KB
testcase_08 AC 30 ms
4,380 KB
testcase_09 AC 18 ms
4,384 KB
testcase_10 AC 46 ms
4,384 KB
testcase_11 AC 43 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 67 ms
4,384 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 10 ms
4,380 KB
testcase_16 AC 120 ms
4,384 KB
testcase_17 AC 408 ms
4,380 KB
testcase_18 AC 409 ms
4,380 KB
testcase_19 AC 1,473 ms
4,380 KB
testcase_20 AC 1,528 ms
4,380 KB
testcase_21 AC 1,460 ms
4,380 KB
testcase_22 AC 388 ms
4,380 KB
testcase_23 AC 387 ms
4,384 KB
testcase_24 AC 423 ms
4,380 KB
testcase_25 AC 399 ms
4,384 KB
testcase_26 AC 1,524 ms
4,380 KB
testcase_27 AC 1,221 ms
4,384 KB
testcase_28 AC 1,737 ms
4,508 KB
testcase_29 AC 409 ms
4,384 KB
testcase_30 AC 409 ms
4,380 KB
testcase_31 AC 408 ms
4,384 KB
testcase_32 AC 407 ms
4,384 KB
testcase_33 AC 440 ms
4,384 KB
testcase_34 AC 468 ms
4,380 KB
testcase_35 AC 1,843 ms
4,380 KB
testcase_36 AC 1,837 ms
4,380 KB
testcase_37 AC 1,862 ms
4,384 KB
testcase_38 AC 1,784 ms
4,384 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 10 ms
4,384 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 3 ms
4,384 KB
testcase_43 AC 5 ms
4,380 KB
testcase_44 AC 16 ms
4,380 KB
testcase_45 AC 3 ms
4,384 KB
testcase_46 AC 11 ms
4,380 KB
testcase_47 AC 392 ms
4,384 KB
testcase_48 AC 383 ms
4,380 KB
testcase_49 AC 452 ms
4,380 KB
testcase_50 AC 399 ms
4,380 KB
testcase_51 AC 344 ms
4,380 KB
testcase_52 AC 214 ms
4,384 KB
testcase_53 AC 335 ms
4,380 KB
testcase_54 AC 9 ms
4,384 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 1 ms
4,380 KB
testcase_57 AC 2 ms
4,384 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;
}
int N;
int A[10000];
int arr[10000];
long long lf[10001];
long long rg[10001];
int main(){
  int K;
  int mx;
  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 20191102-1

// --- original code ---
// int N, A[1d4];
// int arr[1d4];
// ll lf[10001], rg[10001];
// {
//   int mx;
//   ll res = 0;
//   rd(N,A(N));
// 
//   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