結果

問題 No.2488 Mod Sum Maximization
ユーザー hiromi_ayasehiromi_ayase
提出日時 2023-09-29 23:07:39
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,390 bytes
コンパイル時間 5,513 ms
コンパイル使用メモリ 306,932 KB
実行使用メモリ 5,696 KB
最終ジャッジ日時 2023-09-29 23:07:47
合計ジャッジ時間 8,059 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 2 ms
4,380 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/all>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define FAST_IO                \
  ios::sync_with_stdio(false); \
  cin.tie(0);
const i64 INF = 1001001001001001001;
using Modint = atcoder::static_modint<998244353>;

int main() {
  FAST_IO

  int n;
  cin >> n;
  vector a(n, 0LL);
  for (auto i : views::iota(0, n)) {
    cin >> a[i];
  }
  auto maxVal = accumulate(a.begin(), a.end(), -1, [](i64 a, i64 b) { return max(a, b); });
  auto minVal = accumulate(a.begin(), a.end(), INF, [](i64 a, i64 b) { return min(a, b); });
  auto sum = accumulate(a.begin(), a.end(), 0) - maxVal;

  // min min2 max2 max
  // min ... max min2 ... max2

  auto x = -INF;
  auto y = -INF;
  auto z = -INF;
  for (auto i : views::iota(1, n - 1)) {
    y = max(y, x + a[i] % minVal - a[i]);
    x = max(x, maxVal % a[i]);

    z = max(z, maxVal % a[i] + a[i] % minVal - a[i]);
  }


  auto ans = sum + maxVal % minVal;
  ans = max(ans, sum + y);
  ans = max(ans, sum + z);
  // for (auto i : views::iota(1, n)) {
  //   for (auto j : views::iota(i, n - 1)) {

  //     auto minVal2 = a[i];
  //     auto maxVal2 = a[j];
  //     auto cur = sum - maxVal - maxVal2;
  //     cur += maxVal % minVal2 + maxVal2 % minVal;

  //     ans = max(ans, cur);
  //   }
  // }

  cout << ans << endl;
}
0