Submission #257577

# Submission time Handle Problem Language Result Execution time Memory
257577 2020-08-04T12:28:08 Z vaaven Split the sequence (APIO14_sequence) C++14
33 / 100
2000 ms 81528 KB
/*
                                                                                                     
                                             `-:://:::-                                             
                                           `//:-------:/:`                                          
                                          .+:--.......--:+`                                         
                                         `+:--..`````..--//`                                        
                                         .o:--..`` ``..--:o`                                        
                                         .o:--...```..---+/`                                        
                                       `/y+o/---....---:+o.                                         
                                   `...````-os+/:---:/+o/--.`                                       
              `-/+++++/:.      `...`       :h+d+oooo+/+-`   ...                                     
            `/++//:::://++-`....`         -.`//````````:`     `..`                                  
           `o+/::------://o/`           `-` -.          -`       `..`                               
 `---.-o/:./o/::-..``..-ЗАПУСКАЕМ      ..  ..            -`        `...       ``..``                
  `....o+:-++/:--.```..-://s.        `-`  .-              -`          `-o: .-//::::/:-`             
          `:s+/:--....-::/+s-`      .-   `-                -`           -///:--------:/:`           
           ./s+//:::::://oo-``..НЕЙРОННУЮ: СЕТЬ:::::::-`РАБОТЯГИ        `+:--........--:/`          
            .:ooo+++++osso-`    `.:-...`/` ./::-------:/:`   -`         :+--..``````.--:+:...-+:-`  
             `.-/+++++/+-.-`    -.   ``:so:/:--.......--:+`  `-```````o+/+--..`````..--:o/-..:s+:.  
                 ```````:``.. `-`     -` `+:--..`````..--/+-.../.`````..-o:--.......---/o.    `     
                        `:  `:-      -.  .o:--..`` ``..--:o`   `-`      `:o+:--------:+o-`          
                         `-`-...    ..   .o/--...```..--:+/`    `-`     `oy/so/////++o/.`           
                          -/`  `-` `- ``+s/o/:---...---:++.      `-`   .-../d://///:-.`             
                `.---..``-..-    .-/..`````-oo+/:::::/+o+-        `-``-`  `-.  ````                 
             `:++++/+++++-  ..``.-/:`      /y-:/++o++/:.`..`       ./.   `-                         
            -++/::::::://+/..:-``:` ..   `-.`  ```.```    `..`   `..`-` `-                          
       ``  -o//:--....-::/++` -.-`   `-`.-`                 `..`..`  `-.-                           
  -----ss+:++/:--.```..-://s.  /.     `::                    `-:.     ./`                           
  `````/:..+o/::-..``.--:/+s. ..-`   `-``-`                 ..` `-`  `-`-`                          
          `-s+/::-----::/+oo---``-` ..    .:-    ```      .-`     .-.-  `-`                         
           `:oo+//::://+os/..:`..-/:`      :y.-:::::::.`.-`        ./-`  `-`                        
            `./+oooooooo+/.`-    .-:...`.. .//:-------://`        `- `..` `:.                       
              ``.-::::-.``-/`  `-` `-  `oo:+:--.......--:/`      `-    `.:--h.``..```               
                          -.-`.-    .-   `+:--..`````..--//`    `-       /s-//::::::::.             
                         -` `/-      ..  .o:--..`` ``..--:o.```.-        `//:--------://`           
                        -` .-`.-`     -.`-o/--...```..--:+/.``-:....``:-.+:--....`...--:+`          
                       ..`-.   `-.   ``:os:o/:---...---:++.  `-     ``///+:-..``````.--:+-````-.`   
              `.:///////.-`      .:-..` -``-+o+/:::::/+o/.  `-         `:+:-..`````..--:o/:--/ys+-  
            `-++///////+o/. ``....`-.    :` `.:++++++/:.`  .-           -o/---......---/o.   `.`    
           `++//:-----::/+o:..`     .-`   :    ```````    .-           `+so+:--------:++-`          
  `````:-``:o/::-..`..--:/+o`         -.  `-             .-          `../../+o+////+o+:.`           
  -----syo/o+/:--.```..-://s.          .-` `-           .-        `...     ``-:////:-``             
       .` `/s//:--....-::/+s.            -. `-`        .-       `..`                                
           .+o+/:::--:://+s/-..`          .::+y  ```  .-     `..`                                   
            ./oo++////+oso-`   `....       :y-+:::::::/`   ...                                      
             `.:+oooooo/-`         `....-. .//:-------:/:-.`                                        
                ``...``                 /+:+:--.......--:+`                                         
                                         `+:--..`````..--//`                                        
                                         .o:--..`` ``..--:o`                                        
                                         .+/--...```..--:+/`                                        
                                         `-o/:---...---:++.                                         
                                          `-+o+/:---:/+o/.                                          
                                            `.:+oooo+/-.`                                           
                                               ``````                                               
*/
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")
// #pragma GCC optimize("branch-target-load-optimize")
// #pragma GCC optimize("branch-target-load-optimize2")
// #pragma GCC optimize("btr-bb-exclusive")
// #pragma comment(linker, "/STACK:367077216")
#include <iostream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <math.h>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <queue>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define DEBUG
#define fi first
#define se second
#define pqueue priority_queue
#define pb(x) push_back(x)
//#define endl '\n'
#define all(x) x.begin(), x.end()
// #define int long  long
#define mk(a, b) make_pair(a, b)
 
using namespace std;
      
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ull> vull;
typedef vector<ll> vll;
// typedef tuple<ll, ll, ll> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector< vector<ll> > vvll;
typedef vector<char> vc;
      
const int inf = 1e9 + 228;
const ll infll = 1e18;
const ll MOD = 1e9 + 7;
//static const int maxn = 1e6 + 228;
const ld eps = 1e-6;
const ld eps2 = 1e-9;
const ll MOD2 = 998244353;
const ll dosz = 5e5;
const ll SZ = (1<<18);
const ld PI = atan2l(0, -1);
     
void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    // freopen("a.in", "r", stdin);
//    freopen("logs.out", "w", stdout);
}

const int maxn = 1e5 + 228;
int pref[maxn];
int p[maxn][201];

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

void solve(){ 
  int n, k; 
  cin >> n >> k;
  vll dp1(n+1, -1);
  vll dp2(n+1, -1);
  for(int i=1; i<=n; i++){
    cin >> pref[i];
    pref[i] += pref[i-1];
  }
  for(int i=0; i<maxn; i++)
    for(int j=0; j<201; j++)
      p[i][j] = -1;

  for(int i=1; i<n; i++){
    dp1[i] = sum(1, i)*1ll*sum(i+1, n);
  }
  for(int j=2; j<=k; j++){
    for(int i=j; i<n; i++){
      int l = j-1, r = i-1;
      while(r-l>3){
        int m1 = l+(r-l)/3;
        int m2 = r-(r-l)/3;
        ll ans1 = dp1[m1] + sum(m1+1, i)*1ll*sum(i+1, n);
        ll ans2 = dp1[m2] + sum(m2+1, i)*1ll*sum(i+1, n);
        if(ans1>ans2)
          r = m2;
        else
          l = m1;
      }
      for(int d=l; d<=r; d++){
        ll ans1 = dp1[d] + sum(d+1, i)*1ll*sum(i+1, n);
        if(ans1>=dp2[i]){
          dp2[i] = ans1;
          p[i][j] = d;
        }
      }
    }
    dp1 = dp2;
    for(ll &i:dp2)
      i = -1;
  }
  int mx = k;
  for(int i=k; i<n; i++){
    if(dp1[mx]<=dp1[i])
      mx = i;
  }
  vi ans;
  int cur = mx;
  int cnt = k;
  while(cnt){
    ans.pb(cur);
    cur = p[cur][cnt];
    cnt--;
  }
  cout << dp1[mx] << endl;
  reverse(all(ans));
  for(int i:ans)
    cout << i << " ";
}
 
signed main(){
    fast_io();
    // srand(time(NULL));
    // cout << fixed << setprecision(12);
    int q = 1;
    // cin >> q;
    while(q--)
        solve();
}
# Verdict Execution time Memory Grader output
1 Correct 46 ms 79224 KB contestant found the optimal answer: 108 == 108
2 Correct 46 ms 79224 KB contestant found the optimal answer: 999 == 999
3 Correct 46 ms 79224 KB contestant found the optimal answer: 0 == 0
4 Correct 47 ms 79224 KB contestant found the optimal answer: 1542524 == 1542524
5 Correct 46 ms 79224 KB contestant found the optimal answer: 4500000000 == 4500000000
6 Correct 48 ms 79224 KB contestant found the optimal answer: 1 == 1
7 Correct 47 ms 79224 KB contestant found the optimal answer: 1 == 1
8 Correct 46 ms 79224 KB contestant found the optimal answer: 1 == 1
9 Correct 47 ms 79224 KB contestant found the optimal answer: 100400096 == 100400096
10 Correct 46 ms 79292 KB contestant found the optimal answer: 900320000 == 900320000
11 Correct 46 ms 79224 KB contestant found the optimal answer: 3698080248 == 3698080248
12 Correct 49 ms 79224 KB contestant found the optimal answer: 3200320000 == 3200320000
13 Correct 46 ms 79224 KB contestant found the optimal answer: 140072 == 140072
14 Correct 46 ms 79224 KB contestant found the optimal answer: 376041456 == 376041456
15 Correct 46 ms 79148 KB contestant found the optimal answer: 805 == 805
16 Correct 46 ms 79224 KB contestant found the optimal answer: 900189994 == 900189994
17 Correct 52 ms 79224 KB contestant found the optimal answer: 999919994 == 999919994
# Verdict Execution time Memory Grader output
1 Correct 52 ms 79224 KB contestant found the optimal answer: 1093956 == 1093956
2 Correct 51 ms 79224 KB contestant found the optimal answer: 302460000 == 302460000
3 Correct 53 ms 79224 KB contestant found the optimal answer: 122453454361 == 122453454361
4 Correct 52 ms 79224 KB contestant found the optimal answer: 93663683509 == 93663683509
5 Correct 47 ms 79224 KB contestant found the optimal answer: 1005304678 == 1005304678
6 Correct 54 ms 79224 KB contestant found the optimal answer: 933702 == 933702
7 Correct 49 ms 79224 KB contestant found the optimal answer: 25082842857 == 25082842857
8 Correct 47 ms 79232 KB contestant found the optimal answer: 687136 == 687136
9 Correct 46 ms 79224 KB contestant found the optimal answer: 27295930079 == 27295930079
10 Correct 46 ms 79224 KB contestant found the optimal answer: 29000419931 == 29000419931
# Verdict Execution time Memory Grader output
1 Correct 47 ms 79224 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 46 ms 79224 KB contestant found the optimal answer: 311760000 == 311760000
3 Correct 48 ms 79224 KB contestant found the optimal answer: 1989216017013 == 1989216017013
4 Correct 57 ms 79224 KB contestant found the optimal answer: 1499437552673 == 1499437552673
5 Correct 48 ms 79224 KB contestant found the optimal answer: 1019625819 == 1019625819
6 Correct 48 ms 79224 KB contestant found the optimal answer: 107630884 == 107630884
7 Correct 47 ms 79184 KB contestant found the optimal answer: 475357671774 == 475357671774
8 Correct 53 ms 79224 KB contestant found the optimal answer: 193556962 == 193556962
9 Correct 46 ms 79224 KB contestant found the optimal answer: 482389919803 == 482389919803
10 Correct 56 ms 79224 KB contestant found the optimal answer: 490686959791 == 490686959791
# Verdict Execution time Memory Grader output
1 Correct 46 ms 79296 KB contestant found the optimal answer: 21503404 == 21503404
2 Correct 47 ms 79224 KB contestant found the optimal answer: 140412195 == 140412195
3 Correct 69 ms 79224 KB contestant found the optimal answer: 49729674225461 == 49729674225461
4 Correct 47 ms 79224 KB contestant found the optimal answer: 37485571387523 == 37485571387523
5 Correct 71 ms 79228 KB contestant found the optimal answer: 679388326 == 679388326
6 Incorrect 66 ms 79224 KB contestant didn't find the optimal answer: 4699030263 < 4699030287
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 79352 KB contestant found the optimal answer: 1818678304 == 1818678304
2 Correct 51 ms 79352 KB contestant found the optimal answer: 1326260195 == 1326260195
3 Correct 408 ms 79608 KB contestant found the optimal answer: 4973126687469639 == 4973126687469639
4 Correct 50 ms 79480 KB contestant found the optimal answer: 3748491676694116 == 3748491676694116
5 Correct 267 ms 79456 KB contestant found the optimal answer: 1085432199 == 1085432199
6 Incorrect 308 ms 79352 KB contestant didn't find the optimal answer: 514788973815 < 514790755404
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 105 ms 81272 KB contestant found the optimal answer: 19795776960 == 19795776960
2 Correct 105 ms 81272 KB contestant found the optimal answer: 19874432173 == 19874432173
3 Execution timed out 2090 ms 81528 KB Time limit exceeded
4 Halted 0 ms 0 KB -