Submission #58477629


Source Code Expand

#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<int(n); i++)
const i64 INF = 1001001001001001001;
template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; }
template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; }
#include <atcoder/modint>
using Modint = atcoder::static_modint<998244353>;
using namespace std;

void testcase(){
    int N; cin >> N;
    vector<i64> A, B;
    rep(i,N){
        i64 a; cin >> a;
        A.push_back(a);
        swap(A, B);
    }
    vector<i64> PA, PB;
    rep(t,2){
        PA.push_back(0);
        rep(i,A.size()) rep(b,1<<i) PA.push_back(PA[b] + A[i]);
        swap(A, B); swap(PA, PB);
    }
    sort(PA.begin(), PA.end());
    i64 sum = PA.back() + PB.back();
    i64 ans = sum;
    for(i64 pb : PB){
        i64 lbi = lower_bound(PA.begin(), PA.end(), (sum+1) / 2 - pb) - PA.begin();
        if(lbi != 0) chmin(ans, sum - (PA[lbi-1] + pb));
        if(lbi != i64(PA.size())) chmin(ans, (PA[lbi] + pb));
    }
    cout << ans << '\n';
}

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    testcase();
    return 0;
}

Submission Info

Submission Time
Task C - Separated Lunch
User Nachia
Language C++ 17 (gcc 12.2)
Score 300
Code Size 1324 Byte
Status AC
Exec Time 1 ms
Memory 3620 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 30
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3468 KiB
example_01.txt AC 1 ms 3464 KiB
example_02.txt AC 1 ms 3476 KiB
hand_00.txt AC 1 ms 3620 KiB
hand_01.txt AC 1 ms 3496 KiB
hand_02.txt AC 1 ms 3620 KiB
hand_03.txt AC 1 ms 3436 KiB
hand_04.txt AC 1 ms 3344 KiB
hand_05.txt AC 1 ms 3408 KiB
random_00.txt AC 1 ms 3428 KiB
random_01.txt AC 1 ms 3480 KiB
random_02.txt AC 1 ms 3436 KiB
random_03.txt AC 1 ms 3344 KiB
random_04.txt AC 1 ms 3552 KiB
random_05.txt AC 1 ms 3620 KiB
random_06.txt AC 1 ms 3612 KiB
random_07.txt AC 1 ms 3404 KiB
random_08.txt AC 1 ms 3552 KiB
random_09.txt AC 1 ms 3500 KiB
random_10.txt AC 1 ms 3452 KiB
random_11.txt AC 1 ms 3548 KiB
random_12.txt AC 1 ms 3540 KiB
random_13.txt AC 1 ms 3488 KiB
random_14.txt AC 1 ms 3440 KiB
random_15.txt AC 1 ms 3488 KiB
random_16.txt AC 1 ms 3416 KiB
random_17.txt AC 1 ms 3484 KiB
random_18.txt AC 1 ms 3552 KiB
random_19.txt AC 1 ms 3488 KiB
random_20.txt AC 1 ms 3500 KiB