Submission #878250

# Submission time Handle Problem Language Result Execution time Memory
878250 2023-11-24T07:43:55 Z alexdd Bootfall (IZhO17_bootfall) C++17
100 / 100
531 ms 2132 KB
#pragma GCC optimize("O3,unroll-loops")
#include<iostream>
#include<bitset>
#include<algorithm>
using namespace std;
int n,tot;
int a[505];
bitset<250005> dp;
int variante[250005],cntv;
int newv[250005],cntnew;
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]%2!=a[1]%2)
        {
            cout<<0;
            return 0;
        }
        tot+=a[i];
    }
    if(tot%2==1)
    {
        cout<<0;
        return 0;
    }
    sort(a+1,a+1+n);
    for(int i=1;i<=tot;i++)
        if(i%2==a[1]%2)
            variante[++cntv]=i;
    for(int i=0;i<=n;i++)
    {
        if(i>1 && a[i]==a[i-1])
            continue;
        dp.reset();
        dp[0]=1;
        for(int j=1;j<=n;j++)
        {
            if(i!=j)
                dp |= (dp<<a[j]);
        }
        if(i==0)
        {
            if(dp[tot/2]==0)
            {
                cout<<0;
                return 0;
            }
            continue;
        }
        cntnew=0;
        for(int j=1;j<=cntv;j++)
        {
            int x = variante[j];
            if(dp[(tot-a[i]+x)/2])
                newv[++cntnew] = x;
            ///tot - a[i] + x
        }
        cntv=cntnew;
        for(int j=1;j<=cntnew;j++)
            variante[j] = newv[j];
    }
    cout<<cntv<<"\n";
    for(int i=1;i<=cntv;i++)
        cout<<variante[i]<<" ";
    return 0;
}
/**
3
2 2 2
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 9 ms 348 KB Output is correct
22 Correct 11 ms 576 KB Output is correct
23 Correct 6 ms 348 KB Output is correct
24 Correct 16 ms 524 KB Output is correct
25 Correct 3 ms 600 KB Output is correct
26 Correct 3 ms 600 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 2 ms 352 KB Output is correct
29 Correct 2 ms 344 KB Output is correct
30 Correct 0 ms 600 KB Output is correct
31 Correct 10 ms 604 KB Output is correct
32 Correct 18 ms 348 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 3 ms 348 KB Output is correct
36 Correct 20 ms 576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 9 ms 348 KB Output is correct
22 Correct 11 ms 576 KB Output is correct
23 Correct 6 ms 348 KB Output is correct
24 Correct 16 ms 524 KB Output is correct
25 Correct 3 ms 600 KB Output is correct
26 Correct 3 ms 600 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 2 ms 352 KB Output is correct
29 Correct 2 ms 344 KB Output is correct
30 Correct 0 ms 600 KB Output is correct
31 Correct 10 ms 604 KB Output is correct
32 Correct 18 ms 348 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 3 ms 348 KB Output is correct
36 Correct 20 ms 576 KB Output is correct
37 Correct 41 ms 628 KB Output is correct
38 Correct 45 ms 640 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 153 ms 684 KB Output is correct
41 Correct 3 ms 604 KB Output is correct
42 Correct 112 ms 604 KB Output is correct
43 Correct 29 ms 848 KB Output is correct
44 Correct 34 ms 848 KB Output is correct
45 Correct 31 ms 848 KB Output is correct
46 Correct 140 ms 628 KB Output is correct
47 Correct 114 ms 600 KB Output is correct
48 Correct 7 ms 860 KB Output is correct
49 Correct 5 ms 604 KB Output is correct
50 Correct 125 ms 664 KB Output is correct
51 Correct 1 ms 344 KB Output is correct
52 Correct 15 ms 952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 9 ms 348 KB Output is correct
22 Correct 11 ms 576 KB Output is correct
23 Correct 6 ms 348 KB Output is correct
24 Correct 16 ms 524 KB Output is correct
25 Correct 3 ms 600 KB Output is correct
26 Correct 3 ms 600 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 2 ms 352 KB Output is correct
29 Correct 2 ms 344 KB Output is correct
30 Correct 0 ms 600 KB Output is correct
31 Correct 10 ms 604 KB Output is correct
32 Correct 18 ms 348 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 3 ms 348 KB Output is correct
36 Correct 20 ms 576 KB Output is correct
37 Correct 41 ms 628 KB Output is correct
38 Correct 45 ms 640 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 153 ms 684 KB Output is correct
41 Correct 3 ms 604 KB Output is correct
42 Correct 112 ms 604 KB Output is correct
43 Correct 29 ms 848 KB Output is correct
44 Correct 34 ms 848 KB Output is correct
45 Correct 31 ms 848 KB Output is correct
46 Correct 140 ms 628 KB Output is correct
47 Correct 114 ms 600 KB Output is correct
48 Correct 7 ms 860 KB Output is correct
49 Correct 5 ms 604 KB Output is correct
50 Correct 125 ms 664 KB Output is correct
51 Correct 1 ms 344 KB Output is correct
52 Correct 15 ms 952 KB Output is correct
53 Correct 139 ms 716 KB Output is correct
54 Correct 163 ms 756 KB Output is correct
55 Correct 24 ms 1116 KB Output is correct
56 Correct 175 ms 756 KB Output is correct
57 Correct 27 ms 1112 KB Output is correct
58 Correct 238 ms 776 KB Output is correct
59 Correct 142 ms 836 KB Output is correct
60 Correct 0 ms 600 KB Output is correct
61 Correct 147 ms 872 KB Output is correct
62 Correct 73 ms 1104 KB Output is correct
63 Correct 39 ms 1108 KB Output is correct
64 Correct 38 ms 1184 KB Output is correct
65 Correct 12 ms 604 KB Output is correct
66 Correct 44 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 9 ms 348 KB Output is correct
22 Correct 11 ms 576 KB Output is correct
23 Correct 6 ms 348 KB Output is correct
24 Correct 16 ms 524 KB Output is correct
25 Correct 3 ms 600 KB Output is correct
26 Correct 3 ms 600 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 2 ms 352 KB Output is correct
29 Correct 2 ms 344 KB Output is correct
30 Correct 0 ms 600 KB Output is correct
31 Correct 10 ms 604 KB Output is correct
32 Correct 18 ms 348 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 3 ms 348 KB Output is correct
36 Correct 20 ms 576 KB Output is correct
37 Correct 41 ms 628 KB Output is correct
38 Correct 45 ms 640 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 153 ms 684 KB Output is correct
41 Correct 3 ms 604 KB Output is correct
42 Correct 112 ms 604 KB Output is correct
43 Correct 29 ms 848 KB Output is correct
44 Correct 34 ms 848 KB Output is correct
45 Correct 31 ms 848 KB Output is correct
46 Correct 140 ms 628 KB Output is correct
47 Correct 114 ms 600 KB Output is correct
48 Correct 7 ms 860 KB Output is correct
49 Correct 5 ms 604 KB Output is correct
50 Correct 125 ms 664 KB Output is correct
51 Correct 1 ms 344 KB Output is correct
52 Correct 15 ms 952 KB Output is correct
53 Correct 139 ms 716 KB Output is correct
54 Correct 163 ms 756 KB Output is correct
55 Correct 24 ms 1116 KB Output is correct
56 Correct 175 ms 756 KB Output is correct
57 Correct 27 ms 1112 KB Output is correct
58 Correct 238 ms 776 KB Output is correct
59 Correct 142 ms 836 KB Output is correct
60 Correct 0 ms 600 KB Output is correct
61 Correct 147 ms 872 KB Output is correct
62 Correct 73 ms 1104 KB Output is correct
63 Correct 39 ms 1108 KB Output is correct
64 Correct 38 ms 1184 KB Output is correct
65 Correct 12 ms 604 KB Output is correct
66 Correct 44 ms 604 KB Output is correct
67 Correct 334 ms 856 KB Output is correct
68 Correct 2 ms 600 KB Output is correct
69 Correct 60 ms 1876 KB Output is correct
70 Correct 524 ms 1296 KB Output is correct
71 Correct 531 ms 1288 KB Output is correct
72 Correct 0 ms 344 KB Output is correct
73 Correct 0 ms 348 KB Output is correct
74 Correct 114 ms 1876 KB Output is correct
75 Correct 304 ms 1724 KB Output is correct
76 Correct 33 ms 1872 KB Output is correct
77 Correct 64 ms 2132 KB Output is correct