結果

問題 No.1374 Absolute Game
ユーザー vjudge1vjudge1
提出日時 2024-10-19 01:32:25
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,336 bytes
コンパイル時間 2,439 ms
コンパイル使用メモリ 204,876 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-19 01:32:30
合計ジャッジ時間 4,558 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
#define N 100005
typedef long long ll;
typedef unsigned long long ull;
ll n, a[N], s[2], ans;
int main() {
#ifndef ONLINE_JUDGE
freopen("admin.in", "r", stdin);
// freopen("admin.out", "w", stdout);
#endif
scanf("%lld", &n);
for (int i = 1; i <= n; i++)
scanf("%lld", a + i);
sort(a + 1, a + 1 + n);
int l, r, now;
if (a[1] < 0) {
if (a[2] < 0) {
s[0] = s[1] = 0;
now = 0;
for (int i = 1; i <= n; i++, now ^= 1)
s[now] += a[i];
ans = max(ans, abs(s[0]) - abs(s[1]));
}
if (a[n] >= 0) {
s[0] = s[1] = 0;
l = 1, r = n, now = 0;
while (l <= r) {
if (now & 1)
s[0] += a[l++];
else
s[1] += a[r--];
now ^= 1;
}
ans = max(ans, abs(s[0]) - abs(s[1]));
}
}
if (a[n] >= 0) {
if (a[1] < 0) {
s[0] = s[1] = 0;
l = 1, r = n, now = 0;
while (l <= r) {
if (now & 1)
s[0] += a[r--];
else
s[1] += a[l++];
now ^= 1;
}
ans = max(ans, abs(s[0]) - abs(s[1]));
}
if (a[n - 1] >= 0) {
s[0] = s[1] = 0;
now = 0;
for (int i = n; i >= 1; i--, now ^= 1)
s[now] += a[i];
ans = max(ans, abs(s[0]) - abs(s[1]));
}
}
printf("%lld", ans);
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0