結果

問題 No.999 てん vs. ほむ
ユーザー 佐藤竜也佐藤竜也
提出日時 2023-02-17 17:00:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,609 bytes
コンパイル時間 1,592 ms
コンパイル使用メモリ 166,192 KB
実行使用メモリ 5,620 KB
最終ジャッジ日時 2023-09-26 15:28:08
合計ジャッジ時間 5,653 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2(i, n, s) for (int i = (n - 1); i >= (s); i--)
#define all(a)  (a).begin(),(a).end()
#define all_c(a, b) (a).begin(), (a).end(), back_inserter((b))
vector<int> dy = {-1, 0, 1, 0, -1, -1, 1, 1};
vector<int> dx = {0, 1, 0, -1, -1, 1, 1, -1};
const ll INF = numeric_limits<long long>::max();
const ll MOD = 1'000'000'007;
ll unused = INF % MOD;

ll gcd(ll A, ll B) {
    if (B == 0) return A;
    return gcd(B, A % B);
}

ll lcm(ll A, ll B) {
    ll g = gcd(A, B);
    return A / g * B;
}

// 二分検索の雛型
bool binary_search(int N, int A[], int K) {
    int left = 0, right = N - 1;
    while (left <= right) {
        int mid = (left + right) / 2;
        if (A[mid] == K) return true;
        if (A[mid] < K) left = mid + 1;
        else right = mid - 1;
    }
    return false;
}

/*
lower_bound -> if (A[mid] < K)
upper_bound -> if (A[mid] <= K)
*/
int binary_search2(int N, ll A[], ll K) {
    int left = 0, right = N;
    while (left < right) {
        int mid = (left + right) / 2;
        if (A[mid] < K) left = mid + 1;
        else right = mid;
    }
    return right;
}

/* メモ帳
・小数点以下表示 / cout << fixed << setprecision(12) << 
・ルートの計算   / sqrt(A)

・順列全列挙
    do {
        
    } while (next_permutation(V.begin() V.end()));

・bit検索
for (int i = 0; i < (1 << N); i++) {
    rep(j, 0, N) {
        int wari = (1 << j);
        if ((i / wari) % 2 == 1) {
            
        }
    }
}
*/

ll N, A[100009], ans = INF * -1, SH[100009], ST[100009], RSH[100009], RST[100009];

int main() {
    cin >> N;
    rep(i, 0, N * 2) cin >> A[i];
    
    SH[0] = 0; ST[0] = 0; RSH[0] = 0; RST[0] = 0;
    rep(i, 0, N * 2) {
        if (i % 2) ST[i / 2 + 1] = ST[i / 2] + A[i];
        else SH[i / 2 + 1] = SH[i / 2] + A[i];
    }
    
    rep2(i, N * 2, 0) {
        if (i % 2) RSH[(N * 2 - i) / 2 + 1] = RSH[(N * 2 - i) / 2] + A[i];
        else RST[(N * 2 - i) / 2] = RST[(N * 2 - i) / 2 - 1] + A[i];
    }
    /*
    rep(i, 1, N + 1) cout << SH[i] << " " << ST[i] << endl;
    cout << "-------------------------\n";
    rep(i, 1, N + 1) cout << RSH[i] << " " << RST[i] << endl;
    cout << "-------------------------\n";
    */
    
    rep(i, 0, N + 1) {
        ans = max(ans, (SH[i] + RSH[N - i]) - (ST[i] + RST[N - i]));
        /*cout << i << " " << ans << " / ";
        cout << SH[i] << " " << RSH[N - i] << " ";
        cout << ST[i] << " " << RST[N - i] << endl;*/
    }
    
    cout << ans << endl;
}
0