Submission #2791278


Source Code Expand

Copy
#include "bits/stdc++.h"

using namespace std;

#define pb push_back
#define mp make_pair
constexpr int INF = 1 << 29;
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;

constexpr int dx[4] = {1, 0, -1, 0};
constexpr int dy[4] = {0, 1, 0, -1};

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector<ll> acc(N + 1);
    for (int i = 0; i < N; i++) {
        acc[i + 1] = acc[i] + A[i];
    }
    ll ans = 1LL << 62;
    int i = 1, k = 3;
    for(int j = 2; j < N - 1; j++) {
        while(i + 1 < j) {
            ll newarea = acc[i + 1] - acc[0];
            ll area = acc[i] - acc[0];
            if (abs(newarea - (acc[j] - newarea)) > abs(area - (acc[j] - area))) break;
            i++;
        }
        while(k + 1 < N) {
            ll newarea = acc[k + 1] - acc[j];
            ll area = acc[k] - acc[j];
            if (abs(newarea - (acc[N] - acc[j] - newarea)) > abs(area - (acc[N] - acc[j] - area))) break;
            k++;
        }
        vector<ll> area;
        area.push_back(acc[i]);
        area.push_back(acc[j] - acc[i]);
        area.push_back(acc[k] - acc[j]);
        area.push_back(acc[N] - acc[k]);
        sort(area.begin(), area.end());
        ans = min(ans, area.back() - area[0]);
    }
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task D - Equal Cut
User kakira
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1424 Byte
Status AC
Exec Time 104 ms
Memory 3328 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 43
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt, subtask_1_19.txt, subtask_1_20.txt, subtask_1_21.txt, subtask_1_22.txt, subtask_1_23.txt, subtask_1_24.txt, subtask_1_25.txt, subtask_1_26.txt, subtask_1_27.txt, subtask_1_28.txt, subtask_1_29.txt, subtask_1_30.txt, subtask_1_31.txt, subtask_1_32.txt, subtask_1_33.txt, subtask_1_34.txt, subtask_1_35.txt, subtask_1_36.txt, subtask_1_37.txt
Case Name Status Exec Time Memory
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
subtask_1_01.txt AC 1 ms 256 KB
subtask_1_02.txt AC 102 ms 3072 KB
subtask_1_03.txt AC 39 ms 1536 KB
subtask_1_04.txt AC 71 ms 2176 KB
subtask_1_05.txt AC 1 ms 256 KB
subtask_1_06.txt AC 11 ms 640 KB
subtask_1_07.txt AC 52 ms 2048 KB
subtask_1_08.txt AC 30 ms 1408 KB
subtask_1_09.txt AC 50 ms 1920 KB
subtask_1_10.txt AC 61 ms 2688 KB
subtask_1_11.txt AC 79 ms 3072 KB
subtask_1_12.txt AC 36 ms 1664 KB
subtask_1_13.txt AC 56 ms 2176 KB
subtask_1_14.txt AC 17 ms 896 KB
subtask_1_15.txt AC 12 ms 640 KB
subtask_1_16.txt AC 35 ms 1920 KB
subtask_1_17.txt AC 30 ms 1664 KB
subtask_1_18.txt AC 3 ms 384 KB
subtask_1_19.txt AC 60 ms 3072 KB
subtask_1_20.txt AC 104 ms 3072 KB
subtask_1_21.txt AC 43 ms 1792 KB
subtask_1_22.txt AC 36 ms 1152 KB
subtask_1_23.txt AC 72 ms 2816 KB
subtask_1_24.txt AC 81 ms 3328 KB
subtask_1_25.txt AC 81 ms 3328 KB
subtask_1_26.txt AC 81 ms 3328 KB
subtask_1_27.txt AC 78 ms 3328 KB
subtask_1_28.txt AC 78 ms 3328 KB
subtask_1_29.txt AC 82 ms 3328 KB
subtask_1_30.txt AC 80 ms 3328 KB
subtask_1_31.txt AC 81 ms 3328 KB
subtask_1_32.txt AC 81 ms 3328 KB
subtask_1_33.txt AC 80 ms 3328 KB
subtask_1_34.txt AC 66 ms 3328 KB
subtask_1_35.txt AC 65 ms 3328 KB
subtask_1_36.txt AC 63 ms 3328 KB
subtask_1_37.txt AC 64 ms 3328 KB