Submission #366141

# Submission time Handle Problem Language Result Execution time Memory
366141 2021-02-13T09:51:45 Z nicolaalexandra Bootfall (IZhO17_bootfall) C++14
28 / 100
1000 ms 122988 KB
#include <bits/stdc++.h>
#define DIM 502
using namespace std;

bool dp_left[DIM][DIM*DIM],dp_right[DIM][DIM*DIM],dp[DIM];
int v[DIM],f[DIM*DIM];
vector <int> sol,w,w2;
int n,i,j,sum_total;

int main (){

    //ifstream cin ("date.in");
    //ofstream cout ("date.out");

    cin>>n;
    for (i=1;i<=n;i++){
        cin>>v[i];
        sum_total += v[i];
    }

    if (sum_total % 2){
        cout<<"0";
        return 0;
    }

    dp[0] = 1;
    for (i=1;i<=n;i++){
        for (j=sum_total-v[i];j>=0;j--){
            if (dp[j])
                dp[j+v[i]] = 1;
        }
    }

    if (!dp[sum_total/2]){
        cout<<"0";
        return 0;
    }

    dp_left[0][0] = 1;
    for (i=1;i<=n;i++){
        memcpy (dp_left[i],dp_left[i-1],sizeof dp_left[i-1]);
        for (j=sum_total-v[i];j>=0;j--){
            if (dp_left[i][j])
                dp_left[i][j+v[i]] = 1;
        }
    }

    dp_right[n+1][0] = 1;
    for (i=n;i;i--){
        memcpy (dp_right[i],dp_right[i+1],sizeof dp_right[i+1]);
        for (j=sum_total-v[i];j>=0;j--){
            if (dp_right[i][j])
                dp_right[i][j+v[i]] = 1;
        }
    }


    for (i=1;i<=n;i++){

        w.clear(); w2.clear();
        for (int j=0;j<=sum_total;j++){
            if (dp_left[i-1][j])
                w.push_back(j);
            if (dp_right[i+1][j])
                w2.push_back(j);
        }

        int sum = sum_total - v[i];
        for (j=1;j<=sum_total;j++){
            if ( (sum + j)%2 )
                continue;

            int val = (sum + j)/2; /// exista suma asta?
            if (dp_left[i-1][val] || dp_right[i+1][val]){
                f[j]++;
                continue;
            }

            int ok = 0;
            for (auto it : w){
                if (it > val)
                    break;

                if (dp_right[i+1][val-it-j]){
                    f[j]++;
                    ok = 1;
                    break;
                }
            }
            if (ok)
                continue;

            for (auto it : w2){
                if (it > val)
                    break;
                if (dp_left[i-1][val-it-j]){
                    f[j]++;
                    break;
                }}}}

    for (i=1;i<=sum_total;i++){
        if (f[i] == n)
            sol.push_back(i);
    }

    cout<<sol.size()<<"\n";
    for (auto it : sol)
        cout<<it<<" ";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2284 KB Output is correct
2 Correct 2 ms 3308 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 2284 KB Output is correct
5 Correct 5 ms 6252 KB Output is correct
6 Correct 3 ms 4332 KB Output is correct
7 Correct 2 ms 3308 KB Output is correct
8 Correct 6 ms 6252 KB Output is correct
9 Correct 4 ms 5228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2284 KB Output is correct
2 Correct 2 ms 3308 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 2284 KB Output is correct
5 Correct 5 ms 6252 KB Output is correct
6 Correct 3 ms 4332 KB Output is correct
7 Correct 2 ms 3308 KB Output is correct
8 Correct 6 ms 6252 KB Output is correct
9 Correct 4 ms 5228 KB Output is correct
10 Correct 9 ms 15212 KB Output is correct
11 Correct 9 ms 15212 KB Output is correct
12 Correct 9 ms 15212 KB Output is correct
13 Correct 8 ms 13164 KB Output is correct
14 Correct 8 ms 14188 KB Output is correct
15 Correct 8 ms 14188 KB Output is correct
16 Correct 9 ms 15212 KB Output is correct
17 Correct 7 ms 9196 KB Output is correct
18 Correct 7 ms 12140 KB Output is correct
19 Correct 8 ms 13164 KB Output is correct
20 Correct 9 ms 15212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2284 KB Output is correct
2 Correct 2 ms 3308 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 2284 KB Output is correct
5 Correct 5 ms 6252 KB Output is correct
6 Correct 3 ms 4332 KB Output is correct
7 Correct 2 ms 3308 KB Output is correct
8 Correct 6 ms 6252 KB Output is correct
9 Correct 4 ms 5228 KB Output is correct
10 Correct 9 ms 15212 KB Output is correct
11 Correct 9 ms 15212 KB Output is correct
12 Correct 9 ms 15212 KB Output is correct
13 Correct 8 ms 13164 KB Output is correct
14 Correct 8 ms 14188 KB Output is correct
15 Correct 8 ms 14188 KB Output is correct
16 Correct 9 ms 15212 KB Output is correct
17 Correct 7 ms 9196 KB Output is correct
18 Correct 7 ms 12140 KB Output is correct
19 Correct 8 ms 13164 KB Output is correct
20 Correct 9 ms 15212 KB Output is correct
21 Correct 25 ms 32000 KB Output is correct
22 Correct 29 ms 36972 KB Output is correct
23 Correct 19 ms 25068 KB Output is correct
24 Correct 41 ms 46828 KB Output is correct
25 Correct 555 ms 47032 KB Output is correct
26 Correct 636 ms 49836 KB Output is correct
27 Correct 945 ms 49772 KB Output is correct
28 Correct 906 ms 50040 KB Output is correct
29 Correct 904 ms 49772 KB Output is correct
30 Correct 47 ms 49772 KB Output is correct
31 Correct 136 ms 49900 KB Output is correct
32 Correct 43 ms 49772 KB Output is correct
33 Correct 93 ms 49900 KB Output is correct
34 Correct 93 ms 49772 KB Output is correct
35 Correct 868 ms 49900 KB Output is correct
36 Correct 51 ms 49772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2284 KB Output is correct
2 Correct 2 ms 3308 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 2284 KB Output is correct
5 Correct 5 ms 6252 KB Output is correct
6 Correct 3 ms 4332 KB Output is correct
7 Correct 2 ms 3308 KB Output is correct
8 Correct 6 ms 6252 KB Output is correct
9 Correct 4 ms 5228 KB Output is correct
10 Correct 9 ms 15212 KB Output is correct
11 Correct 9 ms 15212 KB Output is correct
12 Correct 9 ms 15212 KB Output is correct
13 Correct 8 ms 13164 KB Output is correct
14 Correct 8 ms 14188 KB Output is correct
15 Correct 8 ms 14188 KB Output is correct
16 Correct 9 ms 15212 KB Output is correct
17 Correct 7 ms 9196 KB Output is correct
18 Correct 7 ms 12140 KB Output is correct
19 Correct 8 ms 13164 KB Output is correct
20 Correct 9 ms 15212 KB Output is correct
21 Correct 25 ms 32000 KB Output is correct
22 Correct 29 ms 36972 KB Output is correct
23 Correct 19 ms 25068 KB Output is correct
24 Correct 41 ms 46828 KB Output is correct
25 Correct 555 ms 47032 KB Output is correct
26 Correct 636 ms 49836 KB Output is correct
27 Correct 945 ms 49772 KB Output is correct
28 Correct 906 ms 50040 KB Output is correct
29 Correct 904 ms 49772 KB Output is correct
30 Correct 47 ms 49772 KB Output is correct
31 Correct 136 ms 49900 KB Output is correct
32 Correct 43 ms 49772 KB Output is correct
33 Correct 93 ms 49900 KB Output is correct
34 Correct 93 ms 49772 KB Output is correct
35 Correct 868 ms 49900 KB Output is correct
36 Correct 51 ms 49772 KB Output is correct
37 Correct 563 ms 99564 KB Output is correct
38 Correct 579 ms 99436 KB Output is correct
39 Execution timed out 1092 ms 122988 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2284 KB Output is correct
2 Correct 2 ms 3308 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 2284 KB Output is correct
5 Correct 5 ms 6252 KB Output is correct
6 Correct 3 ms 4332 KB Output is correct
7 Correct 2 ms 3308 KB Output is correct
8 Correct 6 ms 6252 KB Output is correct
9 Correct 4 ms 5228 KB Output is correct
10 Correct 9 ms 15212 KB Output is correct
11 Correct 9 ms 15212 KB Output is correct
12 Correct 9 ms 15212 KB Output is correct
13 Correct 8 ms 13164 KB Output is correct
14 Correct 8 ms 14188 KB Output is correct
15 Correct 8 ms 14188 KB Output is correct
16 Correct 9 ms 15212 KB Output is correct
17 Correct 7 ms 9196 KB Output is correct
18 Correct 7 ms 12140 KB Output is correct
19 Correct 8 ms 13164 KB Output is correct
20 Correct 9 ms 15212 KB Output is correct
21 Correct 25 ms 32000 KB Output is correct
22 Correct 29 ms 36972 KB Output is correct
23 Correct 19 ms 25068 KB Output is correct
24 Correct 41 ms 46828 KB Output is correct
25 Correct 555 ms 47032 KB Output is correct
26 Correct 636 ms 49836 KB Output is correct
27 Correct 945 ms 49772 KB Output is correct
28 Correct 906 ms 50040 KB Output is correct
29 Correct 904 ms 49772 KB Output is correct
30 Correct 47 ms 49772 KB Output is correct
31 Correct 136 ms 49900 KB Output is correct
32 Correct 43 ms 49772 KB Output is correct
33 Correct 93 ms 49900 KB Output is correct
34 Correct 93 ms 49772 KB Output is correct
35 Correct 868 ms 49900 KB Output is correct
36 Correct 51 ms 49772 KB Output is correct
37 Correct 563 ms 99564 KB Output is correct
38 Correct 579 ms 99436 KB Output is correct
39 Execution timed out 1092 ms 122988 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2284 KB Output is correct
2 Correct 2 ms 3308 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 2 ms 2284 KB Output is correct
5 Correct 5 ms 6252 KB Output is correct
6 Correct 3 ms 4332 KB Output is correct
7 Correct 2 ms 3308 KB Output is correct
8 Correct 6 ms 6252 KB Output is correct
9 Correct 4 ms 5228 KB Output is correct
10 Correct 9 ms 15212 KB Output is correct
11 Correct 9 ms 15212 KB Output is correct
12 Correct 9 ms 15212 KB Output is correct
13 Correct 8 ms 13164 KB Output is correct
14 Correct 8 ms 14188 KB Output is correct
15 Correct 8 ms 14188 KB Output is correct
16 Correct 9 ms 15212 KB Output is correct
17 Correct 7 ms 9196 KB Output is correct
18 Correct 7 ms 12140 KB Output is correct
19 Correct 8 ms 13164 KB Output is correct
20 Correct 9 ms 15212 KB Output is correct
21 Correct 25 ms 32000 KB Output is correct
22 Correct 29 ms 36972 KB Output is correct
23 Correct 19 ms 25068 KB Output is correct
24 Correct 41 ms 46828 KB Output is correct
25 Correct 555 ms 47032 KB Output is correct
26 Correct 636 ms 49836 KB Output is correct
27 Correct 945 ms 49772 KB Output is correct
28 Correct 906 ms 50040 KB Output is correct
29 Correct 904 ms 49772 KB Output is correct
30 Correct 47 ms 49772 KB Output is correct
31 Correct 136 ms 49900 KB Output is correct
32 Correct 43 ms 49772 KB Output is correct
33 Correct 93 ms 49900 KB Output is correct
34 Correct 93 ms 49772 KB Output is correct
35 Correct 868 ms 49900 KB Output is correct
36 Correct 51 ms 49772 KB Output is correct
37 Correct 563 ms 99564 KB Output is correct
38 Correct 579 ms 99436 KB Output is correct
39 Execution timed out 1092 ms 122988 KB Time limit exceeded
40 Halted 0 ms 0 KB -