Submission #155646

# Submission time Handle Problem Language Result Execution time Memory
155646 2019-09-29T14:20:10 Z HellAngel Split the sequence (APIO14_sequence) C++14
0 / 100
15 ms 3640 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5 + 7;

int n, k, dp[207][maxn], a[maxn], m;

void Solve(int x)
{
    int cur = x - 1;
    for(int i = x; i <= n; i++)
    {
        while(cur + 1 < i && dp[x - 1][cur] + (a[i] - a[cur]) * a[cur] <= dp[x - 1][cur + 1] + (a[i] - a[cur + 1]) * a[cur + 1])
        {
            cur++;
        }
        dp[x][i] = dp[x - 1][cur] + (a[i] - a[cur]) * a[cur];
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    for(int j = 2; j <= m + 1; j++)
    {
        Solve(j);
    }
    cout << dp[m + 1][n];
}

Compilation message

sequence.cpp: In function 'int32_t main()':
sequence.cpp:25:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:25:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 632 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 3640 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -