結果

問題 No.1374 Absolute Game
ユーザー kk
提出日時 2021-02-10 16:39:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 974 bytes
コンパイル時間 2,047 ms
コンパイル使用メモリ 205,364 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 11:07:47
合計ジャッジ時間 4,589 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 8 ms
4,380 KB
testcase_09 AC 19 ms
4,380 KB
testcase_10 AC 21 ms
4,380 KB
testcase_11 AC 13 ms
4,380 KB
testcase_12 AC 9 ms
4,376 KB
testcase_13 AC 17 ms
4,376 KB
testcase_14 AC 24 ms
4,376 KB
testcase_15 AC 25 ms
4,376 KB
testcase_16 AC 24 ms
4,376 KB
testcase_17 AC 24 ms
4,376 KB
testcase_18 AC 24 ms
4,380 KB
testcase_19 AC 25 ms
4,380 KB
testcase_20 AC 10 ms
4,376 KB
testcase_21 AC 13 ms
4,380 KB
testcase_22 AC 23 ms
4,384 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 5 ms
4,376 KB
testcase_25 AC 5 ms
4,376 KB
testcase_26 AC 9 ms
4,376 KB
testcase_27 AC 11 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const long long INF = 1LL<<60;

long long calc(vector<int> &c, int a, int b) {
  int n = c.size();
  int av = !a ? 0 : n-1;
  int ad = !a ? 1 : -1;
  int bv = !b ? 0 : n-1;
  int bd = !b ? 1 : -1;

  vector<bool> used(n);
  long long x = 0;
  long long y = 0;

  for (int t = 0; t < n; t++) {
    if (t % 2 == 0) {
      while (used[av]) av += ad;
      x += c[av];
      used[av] = true;
    } else {
      while (used[bv]) bv += bd;
      y += c[bv];
      used[bv] = true;
    }
  }
  return abs(x) - abs(y);
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;
  vector<int> c(n);
  for (int i = 0; i < n; i++)
    cin >> c[i];             
  sort(c.begin(), c.end());
  
  long long ret = -INF;
  for (int i = 0; i < 2; i++) {
    long long v = INF;
    for (int j = 0; j < 2; j++) {
      v = min(v, calc(c, i, j));
    }
    ret = max(ret, v);
  }
  cout << ret << endl;
  
  return 0;
}
0