Submission #2774074


Source Code Expand

Copy
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,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;
  for(int j = 1; j < N - 2; j++) {
    int i1 = lower_bound(acc.begin(), acc.begin() + j + 1, acc[j + 1] / 2) - acc.begin() - 1;
    int i2 = i1 - 1;

    int ss = acc[N] - acc[j + 1];
    int k1 = lower_bound(acc.begin() + j + 1, acc.end(), ss / 2 + acc[j + 1]) - acc.begin() - 1;
    int k2 = k1 - 1;
    
    vector<int> I, K;
    I.push_back(i1);
    K.push_back(k1);

    if (i2 >= 0) {
      I.push_back(i2);
    }

    if (k2 > j) {
      K.push_back(k2);
    }
    
    for(int u = 0; u < I.size(); u++) {
      for(int v = 0; v < K.size(); v++) {
        int i = I[u];
        int k = K[v];

        vector<ll> area;
        ll areaB = acc[i + 1];
        ll areaC = acc[j + 1] - acc[i + 1];
        ll areaD = acc[k + 1] - acc[j + 1];
        ll areaE = acc[N] - acc[k + 1];

        area.push_back(areaB);
        area.push_back(areaC);
        area.push_back(areaD);
        area.push_back(areaE);

        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 0
Code Size 2218 Byte
Status WA
Exec Time 220 ms
Memory 3328 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 3
AC × 31
WA × 12
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 WA 170 ms 3072 KB
subtask_1_03.txt WA 81 ms 1536 KB
subtask_1_04.txt WA 120 ms 2176 KB
subtask_1_05.txt WA 1 ms 256 KB
subtask_1_06.txt AC 18 ms 640 KB
subtask_1_07.txt WA 109 ms 2048 KB
subtask_1_08.txt AC 52 ms 1408 KB
subtask_1_09.txt WA 110 ms 1920 KB
subtask_1_10.txt AC 162 ms 2688 KB
subtask_1_11.txt WA 166 ms 3072 KB
subtask_1_12.txt AC 62 ms 1664 KB
subtask_1_13.txt WA 113 ms 2176 KB
subtask_1_14.txt AC 42 ms 896 KB
subtask_1_15.txt AC 25 ms 640 KB
subtask_1_16.txt AC 64 ms 1920 KB
subtask_1_17.txt AC 90 ms 1664 KB
subtask_1_18.txt AC 5 ms 384 KB
subtask_1_19.txt AC 187 ms 3072 KB
subtask_1_20.txt WA 174 ms 3072 KB
subtask_1_21.txt WA 87 ms 1792 KB
subtask_1_22.txt WA 59 ms 1152 KB
subtask_1_23.txt WA 146 ms 2816 KB
subtask_1_24.txt AC 138 ms 3328 KB
subtask_1_25.txt AC 142 ms 3328 KB
subtask_1_26.txt AC 163 ms 3328 KB
subtask_1_27.txt AC 215 ms 3328 KB
subtask_1_28.txt AC 213 ms 3328 KB
subtask_1_29.txt AC 218 ms 3328 KB
subtask_1_30.txt AC 209 ms 3328 KB
subtask_1_31.txt AC 220 ms 3328 KB
subtask_1_32.txt AC 205 ms 3328 KB
subtask_1_33.txt AC 211 ms 3328 KB
subtask_1_34.txt AC 124 ms 3328 KB
subtask_1_35.txt AC 194 ms 3328 KB
subtask_1_36.txt AC 129 ms 3328 KB
subtask_1_37.txt AC 203 ms 3328 KB