結果

問題 No.1374 Absolute Game
ユーザー SSRSSSRS
提出日時 2021-02-05 21:41:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 899 bytes
コンパイル時間 2,340 ms
コンパイル使用メモリ 175,260 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-15 07:30:45
合計ジャッジ時間 4,319 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000000;
int main(){
  int N;
  cin >> N;
  vector<int> c(N);
  for (int i = 0; i < N; i++){
    cin >> c[i];
  }
  sort(c.begin(), c.end());
  vector<long long> ans(4);
  for (int i = 0; i < (1 << 2); i++){
    deque<int> dq;
    for (int i = 0; i < N; i++){
      dq.push_back(c[i]);
    }
    long long a = 0, b = 0;
    for (int j = 0; j < N; j++){
      if (j % 2 == 0){
        if (i % 2 == 0){
          a += dq.front();
          dq.pop_front();
        } else {
          a += dq.back();
          dq.pop_back();;
        }
      } else {
        if (i / 2 % 2 == 0){
          b += dq.front();
          dq.pop_front();
        } else {
          b += dq.back();
          dq.pop_back();
        }
      }
    }
    ans[i] = abs(a) - abs(b);
  }
  cout << max(min(ans[0], ans[2]), min(ans[1], ans[3])) << endl;
}
0