提出 #72032886


ソースコード 拡げる

#include <bits/stdc++.h>

#include <atcoder/all>

using namespace std;
using namespace atcoder;

#define int long long
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int, int> PI;
typedef pair<int, pair<int, int>> PII;
static const int INF = 1010000000000000017LL;
static const double eps = 1e-12;
static const double pi = 3.14159265358979323846;
static const int dx[4] = {1, -1, 0, 0};
static const int dy[4] = {0, 0, 1, -1};
static const int ddx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
static const int ddy[8] = {0, 0, 1, -1, 1, -1, 1, -1};

template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int N;

signed main() {
    cin >> N;
    vector<int> A(N), B(N), C(N);
    vector<int> SA(N + 1, 0), SB(N + 1, 0), SC(N + 1, 0), S(N + 1, 0);
    for (int i = 0; i < N; ++i) cin >> A[i];
    for (int i = 0; i < N; ++i) cin >> B[i];
    for (int i = 0; i < N; ++i) cin >> C[i];
    for (int i = 0; i < N; ++i) {
        SA[i + 1] = SA[i] + A[i];
        SB[i + 1] = SB[i] + B[i];
        SC[i + 1] = SC[i] + C[i];
        S[i + 1] = SB[i + 1] - SC[i + 1];
    }
    auto op = [](int a, int b) { return max(a, b); };
    auto e = []() { return -INF; };
    segtree<int, op, e> seg(S);

    int ans = -INF;
    for (int i = 1; i < N; ++i) {
        int x = SA[i] - SB[i] + SC[N];
        int y = seg.prod(i + 1, N);
        chmax(ans, x + y);
    }
    cout << ans << endl;
}

提出情報

提出日時
問題 D - Tail of Snake
ユーザ tsuyosshi
言語 C++23 (GCC 15.2.0)
得点 400
コード長 1712 Byte
結果 AC
実行時間 180 ms
メモリ 28064 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 38
セット名 テストケース
Sample sample00.txt, sample01.txt, sample02.txt
All sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt, testcase34.txt
ケース名 結果 実行時間 メモリ
sample00.txt AC 1 ms 3584 KiB
sample01.txt AC 1 ms 3416 KiB
sample02.txt AC 1 ms 3404 KiB
testcase00.txt AC 1 ms 3516 KiB
testcase01.txt AC 1 ms 3508 KiB
testcase02.txt AC 1 ms 3384 KiB
testcase03.txt AC 147 ms 27972 KiB
testcase04.txt AC 146 ms 27844 KiB
testcase05.txt AC 147 ms 27848 KiB
testcase06.txt AC 146 ms 27964 KiB
testcase07.txt AC 147 ms 27832 KiB
testcase08.txt AC 146 ms 27796 KiB
testcase09.txt AC 162 ms 27812 KiB
testcase10.txt AC 163 ms 27836 KiB
testcase11.txt AC 163 ms 28012 KiB
testcase12.txt AC 147 ms 27924 KiB
testcase13.txt AC 146 ms 27892 KiB
testcase14.txt AC 147 ms 27872 KiB
testcase15.txt AC 124 ms 27844 KiB
testcase16.txt AC 125 ms 27924 KiB
testcase17.txt AC 59 ms 10660 KiB
testcase18.txt AC 160 ms 26024 KiB
testcase19.txt AC 180 ms 27776 KiB
testcase20.txt AC 124 ms 18932 KiB
testcase21.txt AC 104 ms 16964 KiB
testcase22.txt AC 179 ms 27812 KiB
testcase23.txt AC 27 ms 6816 KiB
testcase24.txt AC 130 ms 19276 KiB
testcase25.txt AC 180 ms 28064 KiB
testcase26.txt AC 102 ms 19124 KiB
testcase27.txt AC 129 ms 26172 KiB
testcase28.txt AC 143 ms 27932 KiB
testcase29.txt AC 96 ms 18380 KiB
testcase30.txt AC 102 ms 18972 KiB
testcase31.txt AC 144 ms 27940 KiB
testcase32.txt AC 137 ms 27076 KiB
testcase33.txt AC 116 ms 20812 KiB
testcase34.txt AC 145 ms 27924 KiB