Contest Duration: - (local time) (100 minutes) Back to Home

Submission #3824038

Source Code Expand

Copy
```#include <bits/stdc++.h>

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
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;
for (int b = 0; b <= N; b++) {
int a1 = lower_bound(all(acc), acc[b] / 2) - acc.begin();
int c1 = lower_bound(all(acc), (acc[N] - acc[b]) / 2 + acc[b]) - acc.begin();
int a2 = a1 - 1;
int c2 = c1 - 1;
vector<ll> I1 = {a1}, I2 = {c1};
if (a2 >= 0) I1.push_back(a2);
if (c2 >= 0) I2.push_back(c2);
for (int i1 = 0; i1 < I1.size(); i1++) {
for (int i2 = 0; i2 < I2.size(); i2++) {
int a = I1[i1];
int c = I2[i2];
vector<ll> S = {acc[N] - acc[c], acc[c] - acc[b], acc[b] - acc[a], acc[a]};
sort(all(S));
ans = min(ans, abs(S[0] - S.back()));
}
}
}
cout << ans << endl;
}

int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
solve();
return 0;
}```

#### Submission Info

Submission Time 2018-12-19 21:43:25+0900 D - Equal Cut kakira C++14 (GCC 5.4.1) 600 1903 Byte AC 98 ms 3456 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
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 94 ms 3072 KB
subtask_1_03.txt AC 43 ms 1536 KB
subtask_1_04.txt AC 65 ms 2176 KB
subtask_1_05.txt AC 1 ms 256 KB
subtask_1_06.txt AC 13 ms 640 KB
subtask_1_07.txt AC 58 ms 2048 KB
subtask_1_08.txt AC 35 ms 1408 KB
subtask_1_09.txt AC 58 ms 2048 KB
subtask_1_10.txt AC 74 ms 2688 KB
subtask_1_11.txt AC 87 ms 3072 KB
subtask_1_12.txt AC 45 ms 1664 KB
subtask_1_13.txt AC 60 ms 2176 KB
subtask_1_14.txt AC 19 ms 896 KB
subtask_1_15.txt AC 13 ms 640 KB
subtask_1_16.txt AC 50 ms 1920 KB
subtask_1_17.txt AC 42 ms 1664 KB
subtask_1_18.txt AC 4 ms 384 KB
subtask_1_19.txt AC 89 ms 3200 KB
subtask_1_20.txt AC 97 ms 3200 KB
subtask_1_21.txt AC 49 ms 1792 KB
subtask_1_22.txt AC 33 ms 1280 KB
subtask_1_23.txt AC 79 ms 2816 KB
subtask_1_24.txt AC 95 ms 3456 KB
subtask_1_25.txt AC 97 ms 3328 KB
subtask_1_26.txt AC 94 ms 3456 KB
subtask_1_27.txt AC 96 ms 3328 KB
subtask_1_28.txt AC 93 ms 3328 KB
subtask_1_29.txt AC 96 ms 3328 KB
subtask_1_30.txt AC 98 ms 3456 KB
subtask_1_31.txt AC 95 ms 3328 KB
subtask_1_32.txt AC 97 ms 3456 KB
subtask_1_33.txt AC 94 ms 3328 KB
subtask_1_34.txt AC 92 ms 3328 KB
subtask_1_35.txt AC 95 ms 3456 KB
subtask_1_36.txt AC 93 ms 3456 KB
subtask_1_37.txt AC 91 ms 3456 KB