結果
問題 | No.1374 Absolute Game |
ユーザー |
![]() |
提出日時 | 2024-10-19 01:39:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,582 bytes |
コンパイル時間 | 1,867 ms |
コンパイル使用メモリ | 172,864 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-10-19 01:39:22 |
合計ジャッジ時間 | 3,386 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 2 |
other | WA * 26 |
ソースコード
#include<bits/stdc++.h>using namespace std;using ll = long long;//using LL = __int128#define pi pair<ll, ll>#define fi first#define se second#define N 111111#define inf 0x3f3f3f3f3f3f3f3fll n, a[N], vis[11], res[5];void upd(ll &x, int t, ll v){if(t)x = max(x, v);elsex = min(x, v);}bool check(){for(int i = 2 ; i <= n ; i++)if(a[i] * a[i - 1] <= 0)return false;return true;}int main(){freopen("game.in", "r", stdin);freopen("game.out", "w", stdout);scanf("%lld", &n);for(int i = 1 ; i <= n ; i++)scanf("%lld", a + i);if(check()){for(int i = 1 ; i <= n ; i++)a[i] = abs(a[i]);sort(a + 1, a + 1 + n, greater<ll>());ll ans[2] = {0};for(int i = 1 ; i <= n ; i++)ans[i & 1] += a[i];printf("%lld", ans[1] - ans[0]);return 0;}sort(a + 1, a + 1 + n);ll ans[2] = {0};for(int i = 1 ; i <= n ; i++)ans[i & 1] += a[i];res[1] = abs(ans[1]) - abs(ans[0]);memset(ans, 0, sizeof ans);for(int i = n ; i >= 1 ; i--)ans[i & 1] += a[i];res[2] = abs(ans[n & 1]) - abs(ans[(n ^ 1) & 1]);memset(ans, 0, sizeof ans);for(int i = n / 2 ; i >= 1 ; i--)ans[1] += a[i];for(int i = n / 2 + 1 ; i <= n ; i++)ans[0] += a[i];res[3] = abs(ans[0]) - abs(ans[1]);memset(ans, 0, sizeof ans);for(int i = n - n / 2 ; i >= 1 ; i--)ans[0] += a[i];for(int i = n - n / 2 + 1 ; i <= n ; i++)ans[1] += a[i];res[4] = abs(ans[0]) - abs(ans[1]);cerr << res[1] << " " << res[2] << " " << res[3] << " " << res[4] << "\n";printf("%lld", max(min(res[2], res[3]), min(res[1], res[4])));return 0;}/**/