Submission #106407

# Submission time Handle Problem Language Result Execution time Memory
106407 2019-04-18T10:59:19 Z abil Split the sequence (APIO14_sequence) C++14
0 / 100
46 ms 31992 KB
#include <bits/stdc++.h>
#define int long long
#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() )
#define Scan(a) scanf ("%I64d", &a)
#define scan(a) scanf ("%d", &a)
#define pi pair < long long, long long >

using namespace std;

const long long INF = (int)1e18 + 7;
const int N = (int)100007;
const int mod = 1000000007;

int n, k, arr[N], pr[N], par[10007][201];
int dp[N][201];

int calc(int l,int r){
      return pr[l] * (pr[r] - pr[l]);
}
void solve(int k,int l,int r,int optl,int optr){
      if(l > r){
            return;
      }
      int mid = (l + r) >> 1;
      int opt = optl;
      dp[mid][k] = -2;
      for(int i = optl;i < min(mid,optr); i++){
            int cur = dp[i][k - 1] + calc(i,mid);
            if(cur >= dp[mid][k]){
               dp[mid][k] = cur;
               opt = i;
            }
      }
      par[mid][k] = opt;
      solve(k,l,mid - 1,optl,opt);
      solve(k,mid + 1,r,opt,optr);
}
main(){
      cin >> n >> k;
      for(int i = 1;i <= n; i++){
            cin >> arr[i];
            pr[i] = pr[i - 1] + arr[i];
      }
      for(int i = 1;i <= k; i++){
            solve(i,1,n,1,n);
      }
      cout << dp[n][k] << '\n';
      vector<int > ans;
      while(par[n][k]){
            ans.pb(par[n][k]);
            n = par[n][k];
            k--;
      }
      for(int i = ans.size() - 1; i >= 0; i--){
            cout << ans[i] << " ";
      }
}
/*
7 3
4 1 3 4 0 2 3
*/

Compilation message

sequence.cpp:43:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB contestant found the optimal answer: 108 == 108
2 Correct 2 ms 384 KB contestant found the optimal answer: 999 == 999
3 Correct 2 ms 384 KB contestant found the optimal answer: 0 == 0
4 Incorrect 2 ms 384 KB contestant didn't find the optimal answer: 1542523 < 1542524
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB contestant found the optimal answer: 1093956 == 1093956
2 Incorrect 3 ms 512 KB position 1 occurs twice in split scheme
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1024 KB contestant didn't find the optimal answer: 514120000 < 610590000
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3456 KB contestant found the optimal answer: 21503404 == 21503404
2 Incorrect 5 ms 3584 KB contestant didn't find the optimal answer: 130879140 < 140412195
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 31992 KB contestant found the optimal answer: 1818678304 == 1818678304
2 Incorrect 32 ms 31992 KB contestant didn't find the optimal answer: 1225378747 < 1326260195
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 46 ms 3704 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -