ソースコード 拡げる

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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 << 60;
for(int j = 1; j < N; j++) {
int i1 = lower_bound(all(acc), acc[j] / 2) - acc.begin();
int k1 = lower_bound(all(acc), acc[j] + (acc[N] - acc[j]) / 2) - acc.begin();

vector<int> I = {i1};
vector<int> K = {k1};

if (i1 - 1 >= 0) {
I.push_back(i1 - 1);
}
if (k1 - 1 > j) {
K.push_back(k1 - 1);
}

for(int u = 0; u < I.size(); u++) {
for(int v = 0; v < K.size(); v++) {
int i = I[u], k = K[v];
vector<ll> area = {
acc[i],
acc[j] - acc[i],
acc[k] - acc[j],
acc[N] - acc[k]
};
sort(all(area));
ans = min(ans, area.back() - area[0]);
}
}
}
cout << ans << endl;
}

int main() {
#ifdef LOCAL_ENV
cin.exceptions(ios::failbit);
#endif
cin.tie(0);
ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);

solve();
}```

#### 提出情報

提出日時 2019-02-05 00:18:11+0900 D - Equal Cut kakira C++14 (GCC 5.4.1) 600 1992 Byte AC 103 ms 3328 KB

#### ジャッジ結果

セット名 Sample All

 AC × 3
 AC × 43
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
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 42 ms 1536 KB
subtask_1_04.txt AC 63 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 56 ms 2048 KB
subtask_1_08.txt AC 33 ms 1408 KB
subtask_1_09.txt AC 55 ms 2048 KB
subtask_1_10.txt AC 71 ms 2688 KB
subtask_1_11.txt AC 85 ms 3072 KB
subtask_1_12.txt AC 40 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 12 ms 640 KB
subtask_1_16.txt AC 46 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 82 ms 3200 KB
subtask_1_20.txt AC 93 ms 3200 KB
subtask_1_21.txt AC 47 ms 1792 KB
subtask_1_22.txt AC 31 ms 1280 KB
subtask_1_23.txt AC 76 ms 2816 KB
subtask_1_24.txt AC 90 ms 3328 KB
subtask_1_25.txt AC 92 ms 3328 KB
subtask_1_26.txt AC 91 ms 3328 KB
subtask_1_27.txt AC 90 ms 3328 KB
subtask_1_28.txt AC 93 ms 3328 KB
subtask_1_29.txt AC 93 ms 3328 KB
subtask_1_30.txt AC 103 ms 3328 KB
subtask_1_31.txt AC 94 ms 3328 KB
subtask_1_32.txt AC 95 ms 3328 KB
subtask_1_33.txt AC 95 ms 3328 KB
subtask_1_34.txt AC 87 ms 3328 KB
subtask_1_35.txt AC 90 ms 3328 KB
subtask_1_36.txt AC 89 ms 3328 KB
subtask_1_37.txt AC 90 ms 3328 KB