Submission #2854423


Source Code Expand

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

const long long INF = LLONG_MAX / 2;

vector<int> a;
vector<vector<long long> > memo;

long long solve(int i, int j)
{
    if(i == j)
        return a[i];
    if(memo[i][j] != -1)
        return memo[i][j];

    long long ans = -INF;
    for(int k=i+1; k<j; ++k){
        long long tmp = solve(i, k-1) + solve(k+1, j);
        ans = max(ans, tmp);
    }
    return memo[i][j] = ans;
}

void output(int i, int j, int offset, vector<int>& ans)
{
    if(i == j)
        return;

    for(int k=i+1; ; ++k){
        long long x = solve(i, k-1) + solve(k+1, j);
        if(x == solve(i, j)){
            output(i, k-1, offset, ans);
            output(k+1, j, offset + 2, ans);
            ans.push_back(offset + 1);
            return;
        }
    }
}

int main()
{
    int n;
    cin >> n;
    a.resize(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];

    memo.assign(n, vector<long long>(n, -1));
    long long ans = -INF;
    pair<int, int> p;
    for(int i=0; i<n; ++i){
        for(int j=i; j<n; ++j){
            long long tmp = solve(i, j);
            if(ans < tmp){
                ans = tmp;
                p = make_pair(i, j);
            }
        }
    }
    cout << ans << endl;

    vector<int> v;
    for(int i=n-1; i>p.second; --i)
        v.push_back(i);
    for(int i=0; i<p.first; ++i)
        v.push_back(0);
    output(p.first, p.second, 0, v);

    cout << v.size() << endl;
    for(int x : v)
        cout << (x + 1) << endl;

    return 0;
}

Submission Info

Submission Time
Task E - Both Sides Merger
User mamekin
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2033 Byte
Status WA
Exec Time 1778 ms
Memory 10112 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 4
AC × 7
WA × 50
Set Name Test Cases
Sample example_0, example_1, example_2, example_3
All allneg_0, allneg_1, allneg_2, bigans_0, bigans_1, bigans_2, bigans_3, bigans_4, bigans_5, bigans_6, bigans_7, bigans_8, bigans_9, example_0, example_1, example_2, example_3, maxrand_0, maxrand_1, maxrand_10, maxrand_11, maxrand_12, maxrand_13, maxrand_14, maxrand_15, maxrand_16, maxrand_17, maxrand_18, maxrand_19, maxrand_2, maxrand_20, maxrand_21, maxrand_22, maxrand_23, maxrand_24, maxrand_25, maxrand_26, maxrand_27, maxrand_28, maxrand_29, maxrand_3, maxrand_4, maxrand_5, maxrand_6, maxrand_7, maxrand_8, maxrand_9, rand_0, rand_1, rand_2, rand_3, rand_4, rand_5, rand_6, rand_7, rand_8, rand_9
Case Name Status Exec Time Memory
allneg_0 AC 1646 ms 8192 KB
allneg_1 AC 1640 ms 8064 KB
allneg_2 AC 1644 ms 8192 KB
bigans_0 WA 1629 ms 8064 KB
bigans_1 WA 1425 ms 9984 KB
bigans_2 WA 1777 ms 7936 KB
bigans_3 WA 1700 ms 8064 KB
bigans_4 WA 1699 ms 8064 KB
bigans_5 WA 1634 ms 8064 KB
bigans_6 WA 1624 ms 8064 KB
bigans_7 WA 1778 ms 7936 KB
bigans_8 WA 1620 ms 8064 KB
bigans_9 WA 1634 ms 8064 KB
example_0 AC 1 ms 256 KB
example_1 AC 1 ms 256 KB
example_2 AC 1 ms 256 KB
example_3 AC 1 ms 256 KB
maxrand_0 WA 1763 ms 7936 KB
maxrand_1 WA 1639 ms 8064 KB
maxrand_10 WA 1638 ms 8064 KB
maxrand_11 WA 1626 ms 8064 KB
maxrand_12 WA 1551 ms 10112 KB
maxrand_13 WA 1639 ms 8064 KB
maxrand_14 WA 1618 ms 8064 KB
maxrand_15 WA 1770 ms 7936 KB
maxrand_16 WA 1627 ms 8064 KB
maxrand_17 WA 1646 ms 8192 KB
maxrand_18 WA 1625 ms 8064 KB
maxrand_19 WA 1624 ms 8064 KB
maxrand_2 WA 1628 ms 8064 KB
maxrand_20 WA 1756 ms 8064 KB
maxrand_21 WA 1630 ms 8064 KB
maxrand_22 WA 1622 ms 8064 KB
maxrand_23 WA 1647 ms 8192 KB
maxrand_24 WA 1638 ms 8064 KB
maxrand_25 WA 1696 ms 8064 KB
maxrand_26 WA 1771 ms 8064 KB
maxrand_27 WA 1619 ms 8064 KB
maxrand_28 WA 1626 ms 8064 KB
maxrand_29 WA 1621 ms 8064 KB
maxrand_3 WA 1702 ms 8064 KB
maxrand_4 WA 1696 ms 8064 KB
maxrand_5 WA 1626 ms 8064 KB
maxrand_6 WA 1778 ms 7936 KB
maxrand_7 WA 1626 ms 8064 KB
maxrand_8 WA 1644 ms 8192 KB
maxrand_9 WA 1766 ms 7936 KB
rand_0 WA 267 ms 2944 KB
rand_1 WA 20 ms 768 KB
rand_2 WA 2 ms 256 KB
rand_3 WA 136 ms 2048 KB
rand_4 WA 1542 ms 7424 KB
rand_5 WA 80 ms 1536 KB
rand_6 WA 344 ms 3328 KB
rand_7 WA 68 ms 1408 KB
rand_8 WA 269 ms 2944 KB
rand_9 WA 610 ms 4480 KB