Submission #23305

#TimeUsernameProblemLanguageResultExecution timeMemory
23305NurlykhanSplit the sequence (APIO14_sequence)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long 
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()

using namespace std;

const int N = (int) 1e5 + 7;
const int M = (int) 2e6 + 7;#include <bits/stdc++.h>

#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long 
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()

using namespace std;

const int N = (int) 1e4 + 7;
const int M = (int) 2e6 + 7;
const int K = 202;
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const double EPS = (double) 1e-9;
ll dp[N][K], a[N];
int p[N][K];
int n, k;

ll sum(int l, int r) {
    return a[r] - a[l - 1];
}

int main() {
    #define fn "balls"
    #ifdef witch
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
//        freopen(fn".in", "r", stdin);
//        freopen(fn".out", "w", stdout);
    #endif
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    for (int i = 1; i <= n; i++) {
        dp[i][1] = sum(1, i - 1) * sum(i, n);
    }
    for (int i = 2; i <= k; i++) {
        for (int j = i; j <= n; j++) {
            for (int t = 1; t < j; t++) {
                if (dp[j][i] < dp[t][i - 1] + sum(j, n) * sum(t, j - 1)) {
                    dp[j][i] = dp[t][i - 1] + sum(j, n) * sum(t, j - 1);
                    p[j][i] = t;
                }
            }
        }
    }
    int j = 1;
    for (int i = 1; i <= n; i++) {
        if (dp[j][k] < dp[i][k]) j = i;
    }
    cout << dp[j][k] << endl;
    vector<int> ans;
    while (j > 1 && k > 0) {
        ans.pb(j);
        j = p[j][k];
        k--;
    }
    reverse(all(ans));
    for (auto it : ans) cout << it - 1 << " ";
    return 0;
}
const int K = 202;
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const double EPS = (double) 1e-9;
ll dp[N][K], a[N];
int p[N][K];
int n, k;

ll sum(int l, int r) {
    return a[r] - a[l - 1];
}

int main() {
    #define fn "balls"
    #ifdef witch
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
//        freopen(fn".in", "r", stdin);
//        freopen(fn".out", "w", stdout);
    #endif
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    for (int i = 1; i <= n; i++) {
        dp[i][1] = sum(1, i - 1) * sum(i, n);
    }
    for (int i = 2; i <= k; i++) {
        for (int j = i; j <= n; j++) {
            for (int t = 1; t < j; t++) {
                if (dp[j][i] < dp[t][i - 1] + sum(j, n) * sum(t, j - 1)) {
                    dp[j][i] = dp[t][i - 1] + sum(j, n) * sum(t, j - 1);
                    p[j][i] = t;
                }
            }
        }
    }
    int j = 1;
    for (int i = 1; i <= n; i++) {
        if (dp[j][k] < dp[i][k]) j = i;
    }
    cout << dp[j][k] << endl;
    vector<int> ans;
    while (j > 1 && k > 0) {
        ans.pb(j);
        j = p[j][k];
        k--;
    }
    reverse(all(ans));
    for (auto it : ans) cout << it - 1 << " ";
    return 0;
}

Compilation message (stderr)

sequence.cpp:16:29: error: stray '#' in program
 const int M = (int) 2e6 + 7;#include <bits/stdc++.h>
                             ^
sequence.cpp:16:30: error: 'include' does not name a type
 const int M = (int) 2e6 + 7;#include <bits/stdc++.h>
                              ^
sequence.cpp:30:11: error: redefinition of 'const int N'
 const int N = (int) 1e4 + 7;
           ^
sequence.cpp:15:11: note: 'const int N' previously defined here
 const int N = (int) 1e5 + 7;
           ^
sequence.cpp:31:11: error: redefinition of 'const int M'
 const int M = (int) 2e6 + 7;
           ^
sequence.cpp:16:11: note: 'const int M' previously defined here
 const int M = (int) 2e6 + 7;#include <bits/stdc++.h>
           ^
sequence.cpp:86:11: error: redefinition of 'const int K'
 const int K = 202;
           ^
sequence.cpp:32:11: note: 'const int K' previously defined here
 const int K = 202;
           ^
sequence.cpp:87:10: error: redefinition of 'const long long int LINF'
 const ll LINF = (ll) 1e18;
          ^
sequence.cpp:33:10: note: 'const long long int LINF' previously defined here
 const ll LINF = (ll) 1e18;
          ^
sequence.cpp:88:11: error: redefinition of 'const int INF'
 const int INF = (int) 1e9 + 7;
           ^
sequence.cpp:34:11: note: 'const int INF' previously defined here
 const int INF = (int) 1e9 + 7;
           ^
sequence.cpp:89:14: error: redefinition of 'const double EPS'
 const double EPS = (double) 1e-9;
              ^
sequence.cpp:35:14: note: 'const double EPS' previously defined here
 const double EPS = (double) 1e-9;
              ^
sequence.cpp:90:11: error: redefinition of 'long long int dp [100007][202]'
 ll dp[N][K], a[N];
           ^
sequence.cpp:36:4: note: 'long long int dp [100007][202]' previously declared here
 ll dp[N][K], a[N];
    ^
sequence.cpp:90:17: error: redefinition of 'long long int a [100007]'
 ll dp[N][K], a[N];
                 ^
sequence.cpp:36:14: note: 'long long int a [100007]' previously declared here
 ll dp[N][K], a[N];
              ^
sequence.cpp:91:11: error: redefinition of 'int p [100007][202]'
 int p[N][K];
           ^
sequence.cpp:37:5: note: 'int p [100007][202]' previously declared here
 int p[N][K];
     ^
sequence.cpp:92:5: error: redefinition of 'int n'
 int n, k;
     ^
sequence.cpp:38:5: note: 'int n' previously declared here
 int n, k;
     ^
sequence.cpp:92:8: error: redefinition of 'int k'
 int n, k;
        ^
sequence.cpp:38:8: note: 'int k' previously declared here
 int n, k;
        ^
sequence.cpp: In function 'long long int sum(int, int)':
sequence.cpp:94:4: error: redefinition of 'long long int sum(int, int)'
 ll sum(int l, int r) {
    ^
sequence.cpp:40:4: note: 'long long int sum(int, int)' previously defined here
 ll sum(int l, int r) {
    ^
sequence.cpp: In function 'int main()':
sequence.cpp:98:5: error: redefinition of 'int main()'
 int main() {
     ^
sequence.cpp:44:5: note: 'int main()' previously defined here
 int main() {
     ^