Submission #37626

#TimeUsernameProblemLanguageResultExecution timeMemory
37626antimirageSplit the sequence (APIO14_sequence)C++14
39 / 100
156 ms13864 KiB
#include <iostream>
#include <vector>
#include <deque>
#include <math.h>
#include <set>
#include <iomanip>
#include <time.h>
#include <list>
#include <stdio.h>
#include <queue>
#include <map>
#include <algorithm>
#include <assert.h>
#include <memory.h>

#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )

using namespace std;

const int N = 1005;

int n, k, ar[N], p[N][N];

long long dp[N][N], pref[N];

inline int max( long long a, long long b)
{
    return a < b ? b : a;
}

main ()
{
    cin >> n >> k;

    k++;

    for (int i = 1; i <= n; i++)
        scanf("%d", &ar[i]), pref[i] = pref[i - 1] + ar[i];

    for (int i = 1; i <= k; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            for (int l = j; l >= 1; l--)
            {
                if (dp[i][j] < dp[i - 1][l - 1] + (pref[j] - pref[l - 1]) * (pref[n] - pref[j]) )
                {
                    dp[i][j] = dp[i - 1][l - 1] + (pref[j] - pref[l - 1]) * (pref[n] - pref[j]);
                    p[i][j] = l - 1;
                }
            }
        }
    }
    cout << dp[k][n] << endl;

    while (k > 1)
    {
        printf("%d ", p[k][n]);
        n = p[k][n];
        k--;
    }
}
/**
7 3
4 1 3 4 0 2 3
**/

Compilation message (stderr)

sequence.cpp:36:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main ()
       ^
sequence.cpp: In function 'int main()':
sequence.cpp:43:59: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &ar[i]), pref[i] = pref[i - 1] + ar[i];
                                                           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...