結果

問題 No.919 You Are A Project Manager
ユーザー krotonkroton
提出日時 2019-10-25 22:26:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,515 ms / 3,000 ms
コード長 3,014 bytes
コンパイル時間 1,137 ms
コンパイル使用メモリ 106,856 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-10 01:00:29
合計ジャッジ時間 29,108 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 856 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 77 ms
4,384 KB
testcase_05 AC 93 ms
4,380 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 427 ms
4,384 KB
testcase_08 AC 50 ms
4,384 KB
testcase_09 AC 33 ms
4,384 KB
testcase_10 AC 72 ms
4,380 KB
testcase_11 AC 79 ms
4,384 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 110 ms
4,384 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 16 ms
4,380 KB
testcase_16 AC 196 ms
4,380 KB
testcase_17 AC 703 ms
4,380 KB
testcase_18 AC 702 ms
4,380 KB
testcase_19 AC 857 ms
4,384 KB
testcase_20 AC 1,321 ms
4,384 KB
testcase_21 AC 842 ms
4,380 KB
testcase_22 AC 458 ms
4,380 KB
testcase_23 AC 429 ms
4,380 KB
testcase_24 AC 511 ms
4,380 KB
testcase_25 AC 455 ms
4,380 KB
testcase_26 AC 1,219 ms
4,384 KB
testcase_27 AC 1,038 ms
4,380 KB
testcase_28 AC 1,515 ms
4,384 KB
testcase_29 AC 702 ms
4,384 KB
testcase_30 AC 769 ms
4,380 KB
testcase_31 AC 702 ms
4,384 KB
testcase_32 AC 723 ms
4,380 KB
testcase_33 AC 497 ms
4,380 KB
testcase_34 AC 500 ms
4,380 KB
testcase_35 AC 1,420 ms
4,384 KB
testcase_36 AC 1,428 ms
4,384 KB
testcase_37 AC 1,426 ms
4,384 KB
testcase_38 AC 1,422 ms
4,384 KB
testcase_39 AC 2 ms
4,384 KB
testcase_40 AC 16 ms
4,380 KB
testcase_41 AC 3 ms
4,380 KB
testcase_42 AC 4 ms
4,384 KB
testcase_43 AC 7 ms
4,380 KB
testcase_44 AC 28 ms
4,384 KB
testcase_45 AC 4 ms
4,380 KB
testcase_46 AC 20 ms
4,384 KB
testcase_47 AC 457 ms
4,384 KB
testcase_48 AC 443 ms
4,380 KB
testcase_49 AC 527 ms
4,384 KB
testcase_50 AC 450 ms
4,384 KB
testcase_51 AC 421 ms
4,380 KB
testcase_52 AC 316 ms
4,384 KB
testcase_53 AC 423 ms
4,388 KB
testcase_54 AC 17 ms
4,384 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 2 ms
4,380 KB
testcase_57 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

const int B = 500;

const ll INF = 1ll << 60;

template <class T>
vector<T> sumup(const vector<T>& a) {
  int N = a.size();
  vector<T> res(N + 1);
  for (int i = 0; i < N; i++) res[i + 1] = res[i] + a[i];
  return res;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<int> A(N);
    for (int& x : A) cin >> x;
    vec<int, 2> bucket((N + B - 1) / B);
    vector<int> nums = A;
    for (int i = 0; i < N; i++) {
      bucket[i / B].push_back(A[i]);
    }
    sort(nums.begin(), nums.end());
    for (int i = 0; i < N / B; i++) sort(bucket[i].begin(), bucket[i].end());
    auto query = [&](int l, int r, int k) {
      int lb = -1, ub = N - 1;
      while (ub - lb > 1) {
        int md = (lb + ub) / 2;
        int x = nums[md];
        int tl = l, tr = r, c = 0;
        while (tl < tr && tl % B != 0)
          if (A[tl++] <= x) c++;
        while (tl < tr && tr % B != 0)
          if (A[--tr] <= x) c++;
        while (tl < tr) {
          int b = tl / B;
          c += upper_bound(bucket[b].begin(), bucket[b].end(), x) - bucket[b].begin();
          tl += B;
        }
        if (c >= k)
          ub = md;
        else
          lb = md;
      }
      return nums[ub];
    };
    ll res = 0;
    for (int K = 1; K <= N; K++) {
      vector<ll> L(N / K), R(N / K);
      for (int l = 0, i = 0; l + K <= N; l += K, i++) L[i] = query(l, l + K, (K + 1) / 2);
      for (int r = N, i = 0; r - K >= 0; r -= K, i++) R[i] = query(r - K, r, (K + 1) / 2);
      auto sumL = sumup(L);
      auto sumR = sumup(R);
      auto maxL = sumL;
      for (int i = 1; i < maxL.size(); i++) maxL[i] = max(maxL[i - 1], maxL[i]);
      auto maxR = sumR;
      for (int i = 1; i < maxR.size(); i++) maxR[i] = max(maxR[i - 1], maxR[i]);
      for (int l = 0; l <= N / K; l++) {
        chmax(res, K * (maxL[l] + maxR[N / K - l]));
      }
    }
    cout << res << endl;
  }
  return 0;
}
0