Submission #2776590


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,a[200001];
ll ans=2e14,sum[200001],INF=2e14;
int search(int l,int r,int nl,int nr)
{
    if(l==r)
        return l;
    int mid=l+r>>1;
    if(sum[nr]-sum[mid]>sum[mid]-sum[nl-1])
    {
        if(mid+1<=r&&abs(sum[nr]-sum[mid+1]-sum[mid+1]+sum[nl-1])<abs(sum[nr]-sum[mid]-sum[mid]+sum[nl-1]))
            return search(mid+1,r,nl,nr);
        else
            return mid;
    }
    else
    {
        if(mid-1>=l&&abs(sum[nr]-sum[mid-1]-sum[mid-1]+sum[nl-1])<abs(sum[nr]-sum[mid]-sum[mid]+sum[nl-1]))
            return search(l,mid-1,nl,nr);
        else
            return mid;
    }
}
ll solve(int x)
{
    ll MAX=0,MIN=INF;
    int sv1=search(1,x-1,1,x),sv2=search(x+1,n,x+1,n);
    MAX=max(max(sum[sv1],sum[x]-sum[sv1]),max(sum[sv2]-sum[x],sum[n]-sum[sv2]));
    MIN=min(min(sum[sv1],sum[x]-sum[sv1]),min(sum[sv2]-sum[x],sum[n]-sum[sv2]));
    return MAX-MIN;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum[i]=sum[i-1]+a[i];
    }
    for(int i=2;i<n-1;i++)
        ans=min(ans,solve(i));
    cout<<ans<<endl;
    return 0;
}

Submission Info

Submission Time
Task D - Equal Cut
User hsl2363
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1200 Byte
Status AC
Exec Time 47 ms
Memory 2560 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:39:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
                          ^

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 45 ms 2304 KB
subtask_1_03.txt AC 21 ms 1280 KB
subtask_1_04.txt AC 31 ms 1664 KB
subtask_1_05.txt AC 1 ms 256 KB
subtask_1_06.txt AC 6 ms 512 KB
subtask_1_07.txt AC 26 ms 1536 KB
subtask_1_08.txt AC 15 ms 1152 KB
subtask_1_09.txt AC 26 ms 1536 KB
subtask_1_10.txt AC 32 ms 2048 KB
subtask_1_11.txt AC 41 ms 2304 KB
subtask_1_12.txt AC 18 ms 1280 KB
subtask_1_13.txt AC 28 ms 1664 KB
subtask_1_14.txt AC 8 ms 768 KB
subtask_1_15.txt AC 6 ms 512 KB
subtask_1_16.txt AC 20 ms 1536 KB
subtask_1_17.txt AC 19 ms 1280 KB
subtask_1_18.txt AC 2 ms 256 KB
subtask_1_19.txt AC 40 ms 2432 KB
subtask_1_20.txt AC 45 ms 2432 KB
subtask_1_21.txt AC 24 ms 1408 KB
subtask_1_22.txt AC 16 ms 1024 KB
subtask_1_23.txt AC 39 ms 2176 KB
subtask_1_24.txt AC 42 ms 2560 KB
subtask_1_25.txt AC 42 ms 2560 KB
subtask_1_26.txt AC 42 ms 2560 KB
subtask_1_27.txt AC 40 ms 2560 KB
subtask_1_28.txt AC 40 ms 2560 KB
subtask_1_29.txt AC 43 ms 2560 KB
subtask_1_30.txt AC 47 ms 2560 KB
subtask_1_31.txt AC 45 ms 2560 KB
subtask_1_32.txt AC 45 ms 2560 KB
subtask_1_33.txt AC 46 ms 2560 KB
subtask_1_34.txt AC 39 ms 2560 KB
subtask_1_35.txt AC 44 ms 2560 KB
subtask_1_36.txt AC 37 ms 2560 KB
subtask_1_37.txt AC 43 ms 2560 KB