結果

問題 No.1374 Absolute Game
ユーザー RheoTommyRheoTommy
提出日時 2021-02-05 22:56:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,618 bytes
コンパイル時間 2,394 ms
コンパイル使用メモリ 206,852 KB
実行使用メモリ 5,272 KB
最終ジャッジ日時 2023-09-15 09:51:05
合計ジャッジ時間 4,411 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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.pop_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;
}
0