Submission #8574513


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int main()
{
    int N;
    cin >> N;
    vector<lint> A(N);
    REP(i, N) cin >> A[i];
    lint left = A[0];
    lint right = 0;
    REP(i, N-1) {
        right += A[i+1];
    }
    lint ans = 1e12;
    REP(i, N-1) {
        lint price = 0;
        lint minlen = max(i+1, N-1-i);
        lint left_tmp = left;
        lint right_tmp = right;
        if(left < minlen) {
            left_tmp += minlen - left;
            price += minlen - left;
        }
        if(right < minlen) {
            right_tmp += minlen - right;
            price += minlen - right;
        }

        price += abs(left_tmp - right_tmp);

        if(price < ans) ans = price;
        left += A[i+1];
        right -= A[i+1];
    }

    cout << ans << endl;
}

Submission Info

Submission Time
Task B - Iron Bar Cutting
User Shun_PI
Language C++14 (GCC 5.4.1)
Score 200
Code Size 1106 Byte
Status AC
Exec Time 95 ms
Memory 1792 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 2
AC × 20
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
in01.txt AC 1 ms 256 KB
in02.txt AC 1 ms 256 KB
in03.txt AC 1 ms 256 KB
in04.txt AC 1 ms 256 KB
in05.txt AC 1 ms 256 KB
in06.txt AC 1 ms 256 KB
in07.txt AC 83 ms 1792 KB
in08.txt AC 83 ms 1792 KB
in09.txt AC 83 ms 1792 KB
in10.txt AC 83 ms 1792 KB
in11.txt AC 84 ms 1792 KB
in12.txt AC 83 ms 1792 KB
in13.txt AC 83 ms 1792 KB
in14.txt AC 95 ms 1792 KB
in15.txt AC 83 ms 1792 KB
in16.txt AC 83 ms 1792 KB
in17.txt AC 86 ms 1792 KB
in18.txt AC 1 ms 256 KB
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB