結果
| 問題 |
No.1374 Absolute Game
|
| コンテスト | |
| ユーザー |
RheoTommy
|
| 提出日時 | 2021-02-05 22:03:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,614 bytes |
| コンパイル時間 | 2,045 ms |
| コンパイル使用メモリ | 202,332 KB |
| 最終ジャッジ日時 | 2025-01-18 12:23:00 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 6 WA * 20 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:57:24: warning: ignoring return value of ‘std::deque<_Tp, _Alloc>::reference std::deque<_Tp, _Alloc>::back() [with _Tp = long long int; _Alloc = std::allocator<long long int>; reference = long long int&]’, declared with attribute ‘nodiscard’ [-Wunused-result]
57 | ci.back();
| ~~~~~~~^~
In file included from /usr/include/c++/13/deque:66,
from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:139,
from main.cpp:1:
/usr/include/c++/13/bits/stl_deque.h:1468:7: note: declared here
1468 | back() _GLIBCXX_NOEXCEPT
| ^~~~
ソースコード
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int) n; i++)
using ll = long long;
using namespace std;
const long long INF = 1ll << 60;
void chmax(ll &x, ll y) {
x = max(x, y);
}
int main() {
ll n;
cin >> n;
deque<ll> c;
rep(i, n) {
ll ci;
cin >> ci;
c.push_back(ci);
};
ll ans = -INF;
// big big
{
deque<ll> ci = c;
vector<ll> score(2, 0);
rep(i, n) {
score[i % 2] += ci.front();
ci.pop_front();
}
chmax(ans, abs(score[0]) - abs(score[1]));
}
// big small
{
deque<ll> ci = c;
vector<ll> score(2, 0);
rep(i, n) {
if (i % 2) {
score[i % 2] += ci.front();
ci.pop_front();
} else {
score[i % 2] += ci.back();
ci.pop_back();
}
}
chmax(ans, abs(score[0]) - abs(score[1]));
}
// small big
{
deque<ll> ci = c;
vector<ll> score(2, 0);
rep(i, n) {
if (i % 2) {
score[i % 2] += ci.back();
ci.back();
} else {
score[i % 2] += ci.front();
ci.pop_front();
}
}
chmax(ans, abs(score[0]) - abs(score[1]));
}
// small small
{
deque<ll> ci = c;
vector<ll> score(2, 0);
rep(i, n) {
score[i % 2] += ci.back();
ci.pop_back();
}
chmax(ans, abs(score[0]) - abs(score[1]));
}
cout << ans << endl;
}
RheoTommy