結果
問題 | No.1374 Absolute Game |
ユーザー |
|
提出日時 | 2021-02-10 16:39:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 974 bytes |
コンパイル時間 | 2,213 ms |
コンパイル使用メモリ | 198,656 KB |
最終ジャッジ日時 | 2025-01-18 17:04:15 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 26 |
ソースコード
#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;}