Submission #146153

# Submission time Handle Problem Language Result Execution time Memory
146153 2019-08-22T11:42:13 Z mat_v Split the sequence (APIO14_sequence) C++14
28 / 100
2000 ms 65788 KB
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define mid(l, r) ((l)+(r))/2
#define len(a) (a).length()
#define sz(a) (a).size()
#define xx first
#define yy second
#define inf int(2e9)
#define ff(i, a, b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i, a, b) for(int (i) = (a); (i) >= (b); --(i))
#define maxn 100005

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

template<class T>
void print(const T niz[], const int siz)
{
    for(int i=0;i<siz;i++)
        cout << niz[i] << " ";
    cout << endl;
}

int n,k;
ll niz[maxn];
int smer = 0;
ll dp1[maxn][300];
bool bio1[maxn][300];
int koji1[maxn][300];
ll resi1(int x, int y){
    if(bio1[x][y])return dp1[x][y];
    if(y >= x)return -1e9;
    if(y == 0)return 0;
    ll sum = 0;
    ll tmp = 0;
    ll celsum = 0;
    int de = 0;
    for(int i=1; i<=x; i++)celsum  += niz[i];
    for(int i=1; i<=x-1; i++){
        sum += niz[i];
        if(sum * (celsum - sum) + resi1(i,y-1) > tmp)de = i;
        tmp = max(tmp, sum * (celsum - sum) + resi1(i,y-1));

    }
    bio1[x][y] = 1;
    koji1[x][y] = de;
    return dp1[x][y] = tmp;
}

ll dp2[maxn][300];
bool bio2[maxn][300];
int koji2[maxn][300];
ll resi2(int x, int y){
    if(bio2[x][y])return dp2[x][y];
    if(y == 0)return 0;
    int kolko = n-x+1;
    if(y >= kolko)return -1e9;
    ll sum = 0,tmp = 0, celsum = 0;
    int koji = 0;
    int de = 0;
    for(int i=x; i<=n; i++)celsum += niz[i];
    for(int i=x; i<=n-1; i++){
        sum += niz[i];
        if(sum * (celsum - sum) + resi2(i+1,y-1))de = i;
        tmp = max(tmp, sum * (celsum - sum) + resi2(i+1,y-1));
        //if(x == 1)cout << i << " " << " " << resi2(i+1,y-1) << endl;
    }
    bio2[x][y] = 1;
    koji2[x][y] = de;
    return dp2[x][y] = tmp;
}
vector<int>prvi;
vector<int>drugi;
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    ff(i,1,n)cin >> niz[i];
    ll pom = resi1(n,k);
    ll pom2 = resi2(1,k);
    //cout << pom << " " << pom2 << endl;
    int p = koji1[n][k];
    int d = koji2[1][k];
    int k1 = k-1;
    int k2 = k-1;

    int br = 1;
    int br2 = 1;
    prvi.pb(p);
    drugi.pb(d);
    while(br < k){
        p = koji1[p][k1];
        d = koji2[d][k1];
        k1--;
        br++;
        prvi.pb(p);
        drugi.pb(d);
    }
    cout << pom << endl;
    for(auto c:prvi)cout << c << " ";
    //cout << endl;
    //for(auto c:drugi)cout << c << " ";
    return 0;
}
/*
7 3
4 1 3 4 0 2 3
*/

Compilation message

sequence.cpp: In function 'll resi2(int, int)':
sequence.cpp:62:9: warning: unused variable 'koji' [-Wunused-variable]
     int koji = 0;
         ^~~~
sequence.cpp: In function 'int main()':
sequence.cpp:83:8: warning: unused variable 'pom2' [-Wunused-variable]
     ll pom2 = resi2(1,k);
        ^~~~
sequence.cpp:88:9: warning: unused variable 'k2' [-Wunused-variable]
     int k2 = k-1;
         ^~
sequence.cpp:91:9: warning: unused variable 'br2' [-Wunused-variable]
     int br2 = 1;
         ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB contestant found the optimal answer: 108 == 108
2 Correct 2 ms 376 KB contestant found the optimal answer: 999 == 999
3 Incorrect 2 ms 376 KB Integer 0 violates the range [1, 1]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 888 KB contestant found the optimal answer: 1093956 == 1093956
2 Correct 2 ms 760 KB contestant found the optimal answer: 302460000 == 302460000
3 Correct 3 ms 760 KB contestant found the optimal answer: 122453454361 == 122453454361
4 Correct 3 ms 760 KB contestant found the optimal answer: 93663683509 == 93663683509
5 Correct 3 ms 760 KB contestant found the optimal answer: 1005304678 == 1005304678
6 Correct 2 ms 764 KB contestant found the optimal answer: 933702 == 933702
7 Correct 3 ms 760 KB contestant found the optimal answer: 25082842857 == 25082842857
8 Correct 3 ms 760 KB contestant found the optimal answer: 687136 == 687136
9 Correct 3 ms 760 KB contestant found the optimal answer: 27295930079 == 27295930079
10 Correct 3 ms 760 KB contestant found the optimal answer: 29000419931 == 29000419931
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2040 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 4 ms 1912 KB contestant found the optimal answer: 311760000 == 311760000
3 Correct 4 ms 1912 KB contestant found the optimal answer: 1989216017013 == 1989216017013
4 Correct 4 ms 1912 KB contestant found the optimal answer: 1499437552673 == 1499437552673
5 Correct 22 ms 1912 KB contestant found the optimal answer: 1019625819 == 1019625819
6 Incorrect 12 ms 1912 KB Integer 0 violates the range [1, 199]
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 8056 KB contestant found the optimal answer: 21503404 == 21503404
2 Correct 26 ms 8060 KB contestant found the optimal answer: 140412195 == 140412195
3 Correct 1616 ms 8084 KB contestant found the optimal answer: 49729674225461 == 49729674225461
4 Correct 27 ms 8028 KB contestant found the optimal answer: 37485571387523 == 37485571387523
5 Correct 1619 ms 8116 KB contestant found the optimal answer: 679388326 == 679388326
6 Correct 1442 ms 7964 KB contestant found the optimal answer: 4699030287 == 4699030287
7 Correct 1616 ms 8024 KB contestant found the optimal answer: 12418819758185 == 12418819758185
8 Correct 1624 ms 8016 KB contestant found the optimal answer: 31093317350 == 31093317350
9 Correct 376 ms 7992 KB contestant found the optimal answer: 12194625429236 == 12194625429236
10 Correct 735 ms 8060 KB contestant found the optimal answer: 12345131038664 == 12345131038664
# Verdict Execution time Memory Grader output
1 Execution timed out 2029 ms 65788 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2016 ms 42736 KB Time limit exceeded
2 Halted 0 ms 0 KB -