結果
問題 |
No.1374 Absolute Game
|
ユーザー |
![]() |
提出日時 | 2024-10-19 01:36:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,342 bytes |
コンパイル時間 | 1,975 ms |
コンパイル使用メモリ | 196,272 KB |
最終ジャッジ日時 | 2025-02-24 21:23:41 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 13 WA * 13 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:12:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 12 | scanf("%lld", &n); | ~~~~~^~~~~~~~~~~~ main.cpp:14:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 14 | scanf("%lld", a + i); | ~~~~~^~~~~~~~~~~~~~~
ソースコード
#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; }