結果

問題 No.999 てん vs. ほむ
ユーザー pekempeypekempey
提出日時 2020-02-28 21:33:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 736 bytes
コンパイル時間 1,642 ms
コンパイル使用メモリ 167,108 KB
実行使用メモリ 7,804 KB
最終ジャッジ日時 2023-08-03 19:42:00
合計ジャッジ時間 3,789 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 73 ms
7,264 KB
testcase_10 AC 23 ms
4,384 KB
testcase_11 AC 16 ms
4,376 KB
testcase_12 AC 33 ms
4,864 KB
testcase_13 AC 79 ms
7,804 KB
testcase_14 AC 79 ms
7,768 KB
testcase_15 AC 79 ms
7,792 KB
testcase_16 AC 81 ms
7,804 KB
testcase_17 AC 53 ms
7,276 KB
testcase_18 AC 52 ms
7,208 KB
testcase_19 AC 52 ms
7,192 KB
testcase_20 AC 53 ms
7,196 KB
testcase_21 AC 78 ms
7,528 KB
testcase_22 AC 76 ms
7,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  n *= 2;
  vector<ll> a(n);
  ll total = 0;
  rep(i, n) {
    cin >> a[i];
    total += a[i];
  }
  vector<ll> even_pref(n + 1);
  for (int i = 0; i + 2 <= n; i += 2) {
    even_pref[i + 2] = even_pref[i] + a[i + 1];
  }
  vector<ll> even_suff(n + 1);
  for (int i = n; i - 2 >= 0; i -= 2) {
    even_suff[i - 2] = even_suff[i] + a[i - 2];
  }
  ll ans = LLONG_MAX;
  for (int i = 0; i <= n; i += 2) {
    ans = min(ans, even_pref[i] + even_suff[i]);
  }
  cout << total - (ans * 2) << endl;
}
0