Submission #534148

# Submission time Handle Problem Language Result Execution time Memory
534148 2022-03-08T01:38:50 Z Deepesson Bootfall (IZhO17_bootfall) C++17
100 / 100
62 ms 2900 KB
#include <bits/stdc++.h>
#define MAX 251000
int array[505];
typedef std::bitset<MAX> bits;
bits permite={};
bool poc[2]={};

///Idea!!!
///Notice that the knapsack will be very similar each time: All elements - 1 of them.
///Can we optimize mergings, considering that many times they will repeat each other???
///Of course we can!!!
///I will use divide and conquer, and in N log N operations I will be able to merge everything necessary, getting the N sets!
///Complexity: O(N^3 log N / 64)
///Around 20 million operations, very fast

///Divide and Conquer
void dnc(int l,int r,int sum, bits atual){
    if(l==r){
        poc[sum&1]=1;
        int meio = sum/2;
        permite&=atual>>meio;
        return;
    }
    int m = (l+r)/2;
    ///Left
    {
        bits lef;
        lef=atual;
        int newsum = sum;
        for(int i=m+1;i<=r;++i){
            lef|=lef<<array[i];
            newsum+=array[i];
        }
        dnc(l,m,newsum,lef);
    }
    ///Right
    {
        bits rig;
        rig=atual;
        int newsum = sum;
        for(int i=l;i<=m;++i){
            rig|=rig<<array[i];
            newsum+=array[i];
        }
        dnc(m+1,r,newsum,rig);
    }
}
int main()
{
    int N;
    std::cin>>N;
    for(int i=0;i!=N;++i)std::cin>>array[i];
    int t=0;
    {
        for(auto&x:array)t+=x;
        if(t&1){
            std::cout<<"0\n";
            return 0;
        }
        bits x = {};
        x[0]=1;
        for(int i=0;i!=N;++i){
            x|=x<<array[i];
        }
        if(!x[t/2]){
            std::cout<<"0\n";
            return 0;
        }
    }
    for(int i=0;i!=MAX;++i)permite[i]=1;
    bits start={};
    start[0]=1;
    dnc(0,N-1,0,start);
    if(poc[0]==poc[1]){
        std::cout<<"0\n";
        return 0;
    }
    std::vector<int> pode;
    for(int i=1;i!=MAX;++i){
        if(permite[i])pode.push_back(i);
    }
    std::cout<<pode.size()<<"\n";
    for(auto&x:pode){
        std::cout<<((x*2)-(array[0]&1))<<" ";
    }
    std::cout<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 3 ms 900 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 716 KB Output is correct
5 Correct 4 ms 972 KB Output is correct
6 Correct 3 ms 844 KB Output is correct
7 Correct 2 ms 844 KB Output is correct
8 Correct 4 ms 972 KB Output is correct
9 Correct 2 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 3 ms 900 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 716 KB Output is correct
5 Correct 4 ms 972 KB Output is correct
6 Correct 3 ms 844 KB Output is correct
7 Correct 2 ms 844 KB Output is correct
8 Correct 4 ms 972 KB Output is correct
9 Correct 2 ms 972 KB Output is correct
10 Correct 4 ms 1100 KB Output is correct
11 Correct 4 ms 1160 KB Output is correct
12 Correct 4 ms 1144 KB Output is correct
13 Correct 3 ms 1100 KB Output is correct
14 Correct 4 ms 1100 KB Output is correct
15 Correct 4 ms 1152 KB Output is correct
16 Correct 5 ms 1100 KB Output is correct
17 Correct 3 ms 1156 KB Output is correct
18 Correct 5 ms 1156 KB Output is correct
19 Correct 5 ms 1148 KB Output is correct
20 Correct 5 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 3 ms 900 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 716 KB Output is correct
5 Correct 4 ms 972 KB Output is correct
6 Correct 3 ms 844 KB Output is correct
7 Correct 2 ms 844 KB Output is correct
8 Correct 4 ms 972 KB Output is correct
9 Correct 2 ms 972 KB Output is correct
10 Correct 4 ms 1100 KB Output is correct
11 Correct 4 ms 1160 KB Output is correct
12 Correct 4 ms 1144 KB Output is correct
13 Correct 3 ms 1100 KB Output is correct
14 Correct 4 ms 1100 KB Output is correct
15 Correct 4 ms 1152 KB Output is correct
16 Correct 5 ms 1100 KB Output is correct
17 Correct 3 ms 1156 KB Output is correct
18 Correct 5 ms 1156 KB Output is correct
19 Correct 5 ms 1148 KB Output is correct
20 Correct 5 ms 1152 KB Output is correct
21 Correct 7 ms 1268 KB Output is correct
22 Correct 8 ms 1356 KB Output is correct
23 Correct 6 ms 1228 KB Output is correct
24 Correct 13 ms 1400 KB Output is correct
25 Correct 11 ms 1400 KB Output is correct
26 Correct 11 ms 1420 KB Output is correct
27 Correct 11 ms 1408 KB Output is correct
28 Correct 10 ms 1416 KB Output is correct
29 Correct 12 ms 1396 KB Output is correct
30 Correct 9 ms 1392 KB Output is correct
31 Correct 12 ms 1356 KB Output is correct
32 Correct 13 ms 1356 KB Output is correct
33 Correct 11 ms 1396 KB Output is correct
34 Correct 11 ms 1356 KB Output is correct
35 Correct 10 ms 1356 KB Output is correct
36 Correct 12 ms 1400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 3 ms 900 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 716 KB Output is correct
5 Correct 4 ms 972 KB Output is correct
6 Correct 3 ms 844 KB Output is correct
7 Correct 2 ms 844 KB Output is correct
8 Correct 4 ms 972 KB Output is correct
9 Correct 2 ms 972 KB Output is correct
10 Correct 4 ms 1100 KB Output is correct
11 Correct 4 ms 1160 KB Output is correct
12 Correct 4 ms 1144 KB Output is correct
13 Correct 3 ms 1100 KB Output is correct
14 Correct 4 ms 1100 KB Output is correct
15 Correct 4 ms 1152 KB Output is correct
16 Correct 5 ms 1100 KB Output is correct
17 Correct 3 ms 1156 KB Output is correct
18 Correct 5 ms 1156 KB Output is correct
19 Correct 5 ms 1148 KB Output is correct
20 Correct 5 ms 1152 KB Output is correct
21 Correct 7 ms 1268 KB Output is correct
22 Correct 8 ms 1356 KB Output is correct
23 Correct 6 ms 1228 KB Output is correct
24 Correct 13 ms 1400 KB Output is correct
25 Correct 11 ms 1400 KB Output is correct
26 Correct 11 ms 1420 KB Output is correct
27 Correct 11 ms 1408 KB Output is correct
28 Correct 10 ms 1416 KB Output is correct
29 Correct 12 ms 1396 KB Output is correct
30 Correct 9 ms 1392 KB Output is correct
31 Correct 12 ms 1356 KB Output is correct
32 Correct 13 ms 1356 KB Output is correct
33 Correct 11 ms 1396 KB Output is correct
34 Correct 11 ms 1356 KB Output is correct
35 Correct 10 ms 1356 KB Output is correct
36 Correct 12 ms 1400 KB Output is correct
37 Correct 20 ms 1644 KB Output is correct
38 Correct 20 ms 1612 KB Output is correct
39 Correct 25 ms 1520 KB Output is correct
40 Correct 30 ms 1748 KB Output is correct
41 Correct 25 ms 1612 KB Output is correct
42 Correct 38 ms 1640 KB Output is correct
43 Correct 39 ms 1860 KB Output is correct
44 Correct 30 ms 1780 KB Output is correct
45 Correct 27 ms 1900 KB Output is correct
46 Correct 26 ms 1612 KB Output is correct
47 Correct 37 ms 1656 KB Output is correct
48 Correct 23 ms 1740 KB Output is correct
49 Correct 28 ms 1512 KB Output is correct
50 Correct 24 ms 1612 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 28 ms 2016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 3 ms 900 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 716 KB Output is correct
5 Correct 4 ms 972 KB Output is correct
6 Correct 3 ms 844 KB Output is correct
7 Correct 2 ms 844 KB Output is correct
8 Correct 4 ms 972 KB Output is correct
9 Correct 2 ms 972 KB Output is correct
10 Correct 4 ms 1100 KB Output is correct
11 Correct 4 ms 1160 KB Output is correct
12 Correct 4 ms 1144 KB Output is correct
13 Correct 3 ms 1100 KB Output is correct
14 Correct 4 ms 1100 KB Output is correct
15 Correct 4 ms 1152 KB Output is correct
16 Correct 5 ms 1100 KB Output is correct
17 Correct 3 ms 1156 KB Output is correct
18 Correct 5 ms 1156 KB Output is correct
19 Correct 5 ms 1148 KB Output is correct
20 Correct 5 ms 1152 KB Output is correct
21 Correct 7 ms 1268 KB Output is correct
22 Correct 8 ms 1356 KB Output is correct
23 Correct 6 ms 1228 KB Output is correct
24 Correct 13 ms 1400 KB Output is correct
25 Correct 11 ms 1400 KB Output is correct
26 Correct 11 ms 1420 KB Output is correct
27 Correct 11 ms 1408 KB Output is correct
28 Correct 10 ms 1416 KB Output is correct
29 Correct 12 ms 1396 KB Output is correct
30 Correct 9 ms 1392 KB Output is correct
31 Correct 12 ms 1356 KB Output is correct
32 Correct 13 ms 1356 KB Output is correct
33 Correct 11 ms 1396 KB Output is correct
34 Correct 11 ms 1356 KB Output is correct
35 Correct 10 ms 1356 KB Output is correct
36 Correct 12 ms 1400 KB Output is correct
37 Correct 20 ms 1644 KB Output is correct
38 Correct 20 ms 1612 KB Output is correct
39 Correct 25 ms 1520 KB Output is correct
40 Correct 30 ms 1748 KB Output is correct
41 Correct 25 ms 1612 KB Output is correct
42 Correct 38 ms 1640 KB Output is correct
43 Correct 39 ms 1860 KB Output is correct
44 Correct 30 ms 1780 KB Output is correct
45 Correct 27 ms 1900 KB Output is correct
46 Correct 26 ms 1612 KB Output is correct
47 Correct 37 ms 1656 KB Output is correct
48 Correct 23 ms 1740 KB Output is correct
49 Correct 28 ms 1512 KB Output is correct
50 Correct 24 ms 1612 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 28 ms 2016 KB Output is correct
53 Correct 28 ms 1860 KB Output is correct
54 Correct 33 ms 1908 KB Output is correct
55 Correct 35 ms 2172 KB Output is correct
56 Correct 29 ms 2016 KB Output is correct
57 Correct 37 ms 2240 KB Output is correct
58 Correct 40 ms 2040 KB Output is correct
59 Correct 34 ms 2012 KB Output is correct
60 Correct 1 ms 388 KB Output is correct
61 Correct 34 ms 2160 KB Output is correct
62 Correct 32 ms 2164 KB Output is correct
63 Correct 32 ms 2140 KB Output is correct
64 Correct 34 ms 2124 KB Output is correct
65 Correct 31 ms 1632 KB Output is correct
66 Correct 34 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 3 ms 900 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 716 KB Output is correct
5 Correct 4 ms 972 KB Output is correct
6 Correct 3 ms 844 KB Output is correct
7 Correct 2 ms 844 KB Output is correct
8 Correct 4 ms 972 KB Output is correct
9 Correct 2 ms 972 KB Output is correct
10 Correct 4 ms 1100 KB Output is correct
11 Correct 4 ms 1160 KB Output is correct
12 Correct 4 ms 1144 KB Output is correct
13 Correct 3 ms 1100 KB Output is correct
14 Correct 4 ms 1100 KB Output is correct
15 Correct 4 ms 1152 KB Output is correct
16 Correct 5 ms 1100 KB Output is correct
17 Correct 3 ms 1156 KB Output is correct
18 Correct 5 ms 1156 KB Output is correct
19 Correct 5 ms 1148 KB Output is correct
20 Correct 5 ms 1152 KB Output is correct
21 Correct 7 ms 1268 KB Output is correct
22 Correct 8 ms 1356 KB Output is correct
23 Correct 6 ms 1228 KB Output is correct
24 Correct 13 ms 1400 KB Output is correct
25 Correct 11 ms 1400 KB Output is correct
26 Correct 11 ms 1420 KB Output is correct
27 Correct 11 ms 1408 KB Output is correct
28 Correct 10 ms 1416 KB Output is correct
29 Correct 12 ms 1396 KB Output is correct
30 Correct 9 ms 1392 KB Output is correct
31 Correct 12 ms 1356 KB Output is correct
32 Correct 13 ms 1356 KB Output is correct
33 Correct 11 ms 1396 KB Output is correct
34 Correct 11 ms 1356 KB Output is correct
35 Correct 10 ms 1356 KB Output is correct
36 Correct 12 ms 1400 KB Output is correct
37 Correct 20 ms 1644 KB Output is correct
38 Correct 20 ms 1612 KB Output is correct
39 Correct 25 ms 1520 KB Output is correct
40 Correct 30 ms 1748 KB Output is correct
41 Correct 25 ms 1612 KB Output is correct
42 Correct 38 ms 1640 KB Output is correct
43 Correct 39 ms 1860 KB Output is correct
44 Correct 30 ms 1780 KB Output is correct
45 Correct 27 ms 1900 KB Output is correct
46 Correct 26 ms 1612 KB Output is correct
47 Correct 37 ms 1656 KB Output is correct
48 Correct 23 ms 1740 KB Output is correct
49 Correct 28 ms 1512 KB Output is correct
50 Correct 24 ms 1612 KB Output is correct
51 Correct 1 ms 332 KB Output is correct
52 Correct 28 ms 2016 KB Output is correct
53 Correct 28 ms 1860 KB Output is correct
54 Correct 33 ms 1908 KB Output is correct
55 Correct 35 ms 2172 KB Output is correct
56 Correct 29 ms 2016 KB Output is correct
57 Correct 37 ms 2240 KB Output is correct
58 Correct 40 ms 2040 KB Output is correct
59 Correct 34 ms 2012 KB Output is correct
60 Correct 1 ms 388 KB Output is correct
61 Correct 34 ms 2160 KB Output is correct
62 Correct 32 ms 2164 KB Output is correct
63 Correct 32 ms 2140 KB Output is correct
64 Correct 34 ms 2124 KB Output is correct
65 Correct 31 ms 1632 KB Output is correct
66 Correct 34 ms 1656 KB Output is correct
67 Correct 40 ms 2040 KB Output is correct
68 Correct 4 ms 332 KB Output is correct
69 Correct 54 ms 2768 KB Output is correct
70 Correct 62 ms 2384 KB Output is correct
71 Correct 51 ms 2368 KB Output is correct
72 Correct 46 ms 1636 KB Output is correct
73 Correct 47 ms 1620 KB Output is correct
74 Correct 59 ms 2828 KB Output is correct
75 Correct 52 ms 2620 KB Output is correct
76 Correct 57 ms 2756 KB Output is correct
77 Correct 54 ms 2900 KB Output is correct