Submission #1022473

#TimeUsernameProblemLanguageResultExecution timeMemory
1022473daffuwuSplit the sequence (APIO14_sequence)C++14
50 / 100
2048 ms44572 KiB
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, k, opt[100002][202];
long long ps[100069], dp[100069][2], val;

int main() 
{
    int i, j, c;
    scanf("%d%d", &n, &k);
    k++;
    for (i=1; i<=n; i++)
    {
        scanf("%lld", ps+i);
        ps[i] += ps[i-1];
        dp[i][0] = -1e15;
    }
    for (c=1; c<=k; c++)
    {
        dp[0][c%2] = -1e15;
        for (i=1; i<=n; i++)
        {
            dp[i][c%2] = -1e15;
            for (j=i-1; j>=0; j--)
            {
                val = dp[j][(c+1)%2]+(ps[i]-ps[j])*ps[j];
                if (val>dp[i][c%2])
                {
                    dp[i][c%2] = val;
                    opt[i][c] = j;
                }
            }
        }
    }
    printf("%lld\n", dp[n][k%2]);
    for (i=n, c=k; c>=2; i=opt[i][c], c--)
    {
        printf("%d ", opt[i][c]);
    }
    printf("\n");
}

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d%d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~
sequence.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         scanf("%lld", ps+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...