Submission #645857

# Submission time Handle Problem Language Result Execution time Memory
645857 2022-09-28T07:45:50 Z boris_mihov Bootfall (IZhO17_bootfall) C++17
28 / 100
1000 ms 844 KB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <bitset>
#include <set>
#include <map>

typedef long long llong;
const int MAXN = 500 + 10;
const int MAXSUM = 500*500*2 + 10;
const int INF  = 1e9;

int a[MAXN], n;
std::vector <int> values;
std::bitset <MAXSUM> bs, ans;
void getBitset(int missing)
{
    bs.reset();
    bs[MAXSUM / 2] = 1;
    for (int i = 1 ; i <= n ; ++i)
    {
        if (i == missing) continue;
        bs = ((bs << a[i]) | (bs >> a[i]));
    }
}

void solve()
{
    ans.set();
    bs[MAXSUM / 2] = 1;
    for (int i = 1 ; i <= n ; ++i)
    {
        bs = ((bs << a[i]) | (bs >> a[i]));
    }

    if (!bs[MAXSUM / 2])
    {
        std::cout << 0 << '\n';
        return;
    }

    for (int i = 1 ; i <= n ; ++i)
    {
        getBitset(i);
        ans &= bs;
    }

    for (int i = 1 ; i <= MAXSUM - MAXSUM/2 - 1 ; ++i)
    {
        if (ans[MAXSUM / 2 + i] || ans[MAXSUM / 2 - i])
        {
            values.push_back(i);
        }
    }

    std::cout << values.size() << '\n';
    for (const int &i : values)
    {
        std::cout << i << ' '; 
    }

    std::cout << '\n';
}

void read()
{
    std::cin >> n;
    for (int i = 1 ; i <= n ; ++i)
    {
        std::cin >> a[i];
    }
}

void fastIO()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}

int main()
{
    fastIO();
    read();
    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 5 ms 724 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 5 ms 712 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 5 ms 724 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 5 ms 712 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 26 ms 788 KB Output is correct
11 Correct 30 ms 784 KB Output is correct
12 Correct 39 ms 724 KB Output is correct
13 Correct 21 ms 808 KB Output is correct
14 Correct 23 ms 788 KB Output is correct
15 Correct 21 ms 724 KB Output is correct
16 Correct 25 ms 724 KB Output is correct
17 Correct 13 ms 712 KB Output is correct
18 Correct 17 ms 724 KB Output is correct
19 Correct 19 ms 804 KB Output is correct
20 Correct 25 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 5 ms 724 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 5 ms 712 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 26 ms 788 KB Output is correct
11 Correct 30 ms 784 KB Output is correct
12 Correct 39 ms 724 KB Output is correct
13 Correct 21 ms 808 KB Output is correct
14 Correct 23 ms 788 KB Output is correct
15 Correct 21 ms 724 KB Output is correct
16 Correct 25 ms 724 KB Output is correct
17 Correct 13 ms 712 KB Output is correct
18 Correct 17 ms 724 KB Output is correct
19 Correct 19 ms 804 KB Output is correct
20 Correct 25 ms 724 KB Output is correct
21 Correct 122 ms 724 KB Output is correct
22 Correct 151 ms 788 KB Output is correct
23 Correct 66 ms 800 KB Output is correct
24 Correct 228 ms 804 KB Output is correct
25 Correct 237 ms 816 KB Output is correct
26 Correct 262 ms 788 KB Output is correct
27 Correct 271 ms 724 KB Output is correct
28 Correct 266 ms 788 KB Output is correct
29 Correct 272 ms 784 KB Output is correct
30 Correct 271 ms 844 KB Output is correct
31 Correct 271 ms 796 KB Output is correct
32 Correct 258 ms 724 KB Output is correct
33 Correct 272 ms 780 KB Output is correct
34 Correct 260 ms 724 KB Output is correct
35 Correct 257 ms 784 KB Output is correct
36 Correct 262 ms 784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 5 ms 724 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 5 ms 712 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 26 ms 788 KB Output is correct
11 Correct 30 ms 784 KB Output is correct
12 Correct 39 ms 724 KB Output is correct
13 Correct 21 ms 808 KB Output is correct
14 Correct 23 ms 788 KB Output is correct
15 Correct 21 ms 724 KB Output is correct
16 Correct 25 ms 724 KB Output is correct
17 Correct 13 ms 712 KB Output is correct
18 Correct 17 ms 724 KB Output is correct
19 Correct 19 ms 804 KB Output is correct
20 Correct 25 ms 724 KB Output is correct
21 Correct 122 ms 724 KB Output is correct
22 Correct 151 ms 788 KB Output is correct
23 Correct 66 ms 800 KB Output is correct
24 Correct 228 ms 804 KB Output is correct
25 Correct 237 ms 816 KB Output is correct
26 Correct 262 ms 788 KB Output is correct
27 Correct 271 ms 724 KB Output is correct
28 Correct 266 ms 788 KB Output is correct
29 Correct 272 ms 784 KB Output is correct
30 Correct 271 ms 844 KB Output is correct
31 Correct 271 ms 796 KB Output is correct
32 Correct 258 ms 724 KB Output is correct
33 Correct 272 ms 780 KB Output is correct
34 Correct 260 ms 724 KB Output is correct
35 Correct 257 ms 784 KB Output is correct
36 Correct 262 ms 784 KB Output is correct
37 Execution timed out 1086 ms 724 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 5 ms 724 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 5 ms 712 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 26 ms 788 KB Output is correct
11 Correct 30 ms 784 KB Output is correct
12 Correct 39 ms 724 KB Output is correct
13 Correct 21 ms 808 KB Output is correct
14 Correct 23 ms 788 KB Output is correct
15 Correct 21 ms 724 KB Output is correct
16 Correct 25 ms 724 KB Output is correct
17 Correct 13 ms 712 KB Output is correct
18 Correct 17 ms 724 KB Output is correct
19 Correct 19 ms 804 KB Output is correct
20 Correct 25 ms 724 KB Output is correct
21 Correct 122 ms 724 KB Output is correct
22 Correct 151 ms 788 KB Output is correct
23 Correct 66 ms 800 KB Output is correct
24 Correct 228 ms 804 KB Output is correct
25 Correct 237 ms 816 KB Output is correct
26 Correct 262 ms 788 KB Output is correct
27 Correct 271 ms 724 KB Output is correct
28 Correct 266 ms 788 KB Output is correct
29 Correct 272 ms 784 KB Output is correct
30 Correct 271 ms 844 KB Output is correct
31 Correct 271 ms 796 KB Output is correct
32 Correct 258 ms 724 KB Output is correct
33 Correct 272 ms 780 KB Output is correct
34 Correct 260 ms 724 KB Output is correct
35 Correct 257 ms 784 KB Output is correct
36 Correct 262 ms 784 KB Output is correct
37 Execution timed out 1086 ms 724 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 724 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 2 ms 724 KB Output is correct
5 Correct 5 ms 724 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 5 ms 712 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
10 Correct 26 ms 788 KB Output is correct
11 Correct 30 ms 784 KB Output is correct
12 Correct 39 ms 724 KB Output is correct
13 Correct 21 ms 808 KB Output is correct
14 Correct 23 ms 788 KB Output is correct
15 Correct 21 ms 724 KB Output is correct
16 Correct 25 ms 724 KB Output is correct
17 Correct 13 ms 712 KB Output is correct
18 Correct 17 ms 724 KB Output is correct
19 Correct 19 ms 804 KB Output is correct
20 Correct 25 ms 724 KB Output is correct
21 Correct 122 ms 724 KB Output is correct
22 Correct 151 ms 788 KB Output is correct
23 Correct 66 ms 800 KB Output is correct
24 Correct 228 ms 804 KB Output is correct
25 Correct 237 ms 816 KB Output is correct
26 Correct 262 ms 788 KB Output is correct
27 Correct 271 ms 724 KB Output is correct
28 Correct 266 ms 788 KB Output is correct
29 Correct 272 ms 784 KB Output is correct
30 Correct 271 ms 844 KB Output is correct
31 Correct 271 ms 796 KB Output is correct
32 Correct 258 ms 724 KB Output is correct
33 Correct 272 ms 780 KB Output is correct
34 Correct 260 ms 724 KB Output is correct
35 Correct 257 ms 784 KB Output is correct
36 Correct 262 ms 784 KB Output is correct
37 Execution timed out 1086 ms 724 KB Time limit exceeded
38 Halted 0 ms 0 KB -