結果

問題 No.2488 Mod Sum Maximization
ユーザー KudeKude
提出日時 2023-09-29 23:21:50
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 611 ms / 2,000 ms
コード長 1,619 bytes
コンパイル時間 3,785 ms
コンパイル使用メモリ 276,200 KB
実行使用メモリ 16,932 KB
最終ジャッジ日時 2023-09-29 23:22:04
合計ジャッジ時間 13,212 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,956 KB
testcase_01 AC 4 ms
7,960 KB
testcase_02 AC 5 ms
8,168 KB
testcase_03 AC 352 ms
15,740 KB
testcase_04 AC 349 ms
16,216 KB
testcase_05 AC 383 ms
15,828 KB
testcase_06 AC 329 ms
15,660 KB
testcase_07 AC 222 ms
11,808 KB
testcase_08 AC 342 ms
16,000 KB
testcase_09 AC 262 ms
11,968 KB
testcase_10 AC 174 ms
12,624 KB
testcase_11 AC 11 ms
8,224 KB
testcase_12 AC 157 ms
11,624 KB
testcase_13 AC 123 ms
10,032 KB
testcase_14 AC 28 ms
8,652 KB
testcase_15 AC 191 ms
11,852 KB
testcase_16 AC 12 ms
8,224 KB
testcase_17 AC 52 ms
9,140 KB
testcase_18 AC 17 ms
8,248 KB
testcase_19 AC 293 ms
11,900 KB
testcase_20 AC 301 ms
15,448 KB
testcase_21 AC 290 ms
12,100 KB
testcase_22 AC 331 ms
16,932 KB
testcase_23 AC 377 ms
15,804 KB
testcase_24 AC 109 ms
9,984 KB
testcase_25 AC 9 ms
8,348 KB
testcase_26 AC 17 ms
8,308 KB
testcase_27 AC 347 ms
11,536 KB
testcase_28 AC 377 ms
11,716 KB
testcase_29 AC 278 ms
11,704 KB
testcase_30 AC 206 ms
9,928 KB
testcase_31 AC 29 ms
8,668 KB
testcase_32 AC 611 ms
11,876 KB
testcase_33 AC 7 ms
7,888 KB
testcase_34 AC 578 ms
15,364 KB
testcase_35 AC 151 ms
9,900 KB
testcase_36 AC 4 ms
7,940 KB
testcase_37 AC 4 ms
8,112 KB
testcase_38 AC 4 ms
7,864 KB
testcase_39 AC 4 ms
8,032 KB
testcase_40 AC 4 ms
8,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI a(n);
  rep(i, n) cin >> a[i];
  ll ans = accumulate(all(a) - 1, 0LL) + a[0];
  vector<char> exists(1000001);
  for (int x : a) exists[x] = true;
  constexpr int INF = 1001001001;
  VI dp(1000001, INF);
  struct S {
    int cost, upto, add;
  };
  auto cmp = [](const S& x, const S& y) {
    return x.cost > y.cost;
  };
  priority_queue<S, vector<S>, decltype(cmp)> q(cmp);
  for (int i = a[0]; i <= a[n - 1]; i++) {
    if (!exists[i]) continue;
    int c = [&] {
      if (i == a[0]) return 0;
      while(q.top().upto <= i) {
        auto [cost, upto, add] = q.top(); q.pop();
        q.push({cost + add, upto + add, add});
      }
      return q.top().cost - i;
    }();
    if (i == a[n - 1]) {
      ans -= c;
      break;
    }
    q.push({c + i + i, i + i, i});
  }
  cout << ans << '\n';
}
0