Submission #340682

# Submission time Handle Problem Language Result Execution time Memory
340682 2020-12-28T07:10:50 Z IZhO_2021_I_want_Silver Bootfall (IZhO17_bootfall) C++14
100 / 100
799 ms 3692 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <stack>
#include <queue>
#include <bitset>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>-

using namespace std;
//using namespace __gnu_pbds;

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

// template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//  order_of_key (k) : Number of items strictly smaller than k .
//  find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define show(a) cerr << #a <<" -> "<< a <<" "
#define nl cerr <<"\n"
//#define int ll

const int N = 3e5 + 5;

int n, a[N], sum, dp[N], cnt[N];
bitset <N> was;
vector <int> ans;

void add(int x) {
    sum += x;
    for (int i = sum; i >= x; --i) {
        dp[i] += dp[i - x];
    }
}
void del(int x) {
    for (int i = x; i <= sum; ++i) {
        dp[i] -= dp[i - x];
    }
    sum -= x;
}

void solve() {
    cin >> n;

    dp[0] = 1;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        add(a[i]);
    }

    bool exist_answer = 0;
    for (int j = 0; j <= sum; ++j) {
        if (dp[j] && sum - j == j) { exist_answer = 1; break; }
    }
    if (!exist_answer) { cout << 0; return; }

    for (int i = 1; i <= n; ++i) {
        del(a[i]);
        for (int j = 0; j <= sum; ++j) {
            if (dp[j]) {
                int Tima = max(sum - j, j) - min(sum - j, j);
                if(!was[Tima]) { ++cnt[Tima]; was[Tima] = 1; }
            }
        }
        for (int j = 0; j <= sum; ++j) { was[j] = 0; }
        add(a[i]);
    }
    for (int i = 1; i < sum; ++i) {
        if (cnt[i] == n) { ans.pb(i); }
    }
    cout << sz(ans) <<"\n";
    for (int i = 0; i < sz(ans); ++i) { cout << ans[i] <<" "; }
}

 main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tests = 1;
	//cin >> tests;
	while (tests --) {
		solve();
	}
	return 0;
}
/*
    Just Chalish!
*/

Compilation message

bootfall.cpp:90:8: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   90 |  main () {
      |        ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 380 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 380 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 4 ms 492 KB Output is correct
25 Correct 7 ms 492 KB Output is correct
26 Correct 7 ms 492 KB Output is correct
27 Correct 6 ms 492 KB Output is correct
28 Correct 6 ms 492 KB Output is correct
29 Correct 7 ms 492 KB Output is correct
30 Correct 5 ms 364 KB Output is correct
31 Correct 6 ms 492 KB Output is correct
32 Correct 4 ms 492 KB Output is correct
33 Correct 6 ms 492 KB Output is correct
34 Correct 8 ms 492 KB Output is correct
35 Correct 6 ms 492 KB Output is correct
36 Correct 4 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 380 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 4 ms 492 KB Output is correct
25 Correct 7 ms 492 KB Output is correct
26 Correct 7 ms 492 KB Output is correct
27 Correct 6 ms 492 KB Output is correct
28 Correct 6 ms 492 KB Output is correct
29 Correct 7 ms 492 KB Output is correct
30 Correct 5 ms 364 KB Output is correct
31 Correct 6 ms 492 KB Output is correct
32 Correct 4 ms 492 KB Output is correct
33 Correct 6 ms 492 KB Output is correct
34 Correct 8 ms 492 KB Output is correct
35 Correct 6 ms 492 KB Output is correct
36 Correct 4 ms 492 KB Output is correct
37 Correct 30 ms 620 KB Output is correct
38 Correct 31 ms 748 KB Output is correct
39 Correct 80 ms 876 KB Output is correct
40 Correct 61 ms 876 KB Output is correct
41 Correct 103 ms 1004 KB Output is correct
42 Correct 51 ms 748 KB Output is correct
43 Correct 95 ms 1260 KB Output is correct
44 Correct 94 ms 1132 KB Output is correct
45 Correct 97 ms 1132 KB Output is correct
46 Correct 49 ms 620 KB Output is correct
47 Correct 55 ms 876 KB Output is correct
48 Correct 98 ms 1132 KB Output is correct
49 Correct 89 ms 904 KB Output is correct
50 Correct 56 ms 876 KB Output is correct
51 Correct 3 ms 492 KB Output is correct
52 Correct 124 ms 1276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 380 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 4 ms 492 KB Output is correct
25 Correct 7 ms 492 KB Output is correct
26 Correct 7 ms 492 KB Output is correct
27 Correct 6 ms 492 KB Output is correct
28 Correct 6 ms 492 KB Output is correct
29 Correct 7 ms 492 KB Output is correct
30 Correct 5 ms 364 KB Output is correct
31 Correct 6 ms 492 KB Output is correct
32 Correct 4 ms 492 KB Output is correct
33 Correct 6 ms 492 KB Output is correct
34 Correct 8 ms 492 KB Output is correct
35 Correct 6 ms 492 KB Output is correct
36 Correct 4 ms 492 KB Output is correct
37 Correct 30 ms 620 KB Output is correct
38 Correct 31 ms 748 KB Output is correct
39 Correct 80 ms 876 KB Output is correct
40 Correct 61 ms 876 KB Output is correct
41 Correct 103 ms 1004 KB Output is correct
42 Correct 51 ms 748 KB Output is correct
43 Correct 95 ms 1260 KB Output is correct
44 Correct 94 ms 1132 KB Output is correct
45 Correct 97 ms 1132 KB Output is correct
46 Correct 49 ms 620 KB Output is correct
47 Correct 55 ms 876 KB Output is correct
48 Correct 98 ms 1132 KB Output is correct
49 Correct 89 ms 904 KB Output is correct
50 Correct 56 ms 876 KB Output is correct
51 Correct 3 ms 492 KB Output is correct
52 Correct 124 ms 1276 KB Output is correct
53 Correct 97 ms 1044 KB Output is correct
54 Correct 132 ms 1260 KB Output is correct
55 Correct 254 ms 1904 KB Output is correct
56 Correct 116 ms 1152 KB Output is correct
57 Correct 281 ms 1904 KB Output is correct
58 Correct 143 ms 1260 KB Output is correct
59 Correct 181 ms 1520 KB Output is correct
60 Correct 6 ms 620 KB Output is correct
61 Correct 201 ms 1648 KB Output is correct
62 Correct 203 ms 1776 KB Output is correct
63 Correct 239 ms 1776 KB Output is correct
64 Correct 213 ms 1776 KB Output is correct
65 Correct 86 ms 748 KB Output is correct
66 Correct 90 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 380 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 4 ms 492 KB Output is correct
25 Correct 7 ms 492 KB Output is correct
26 Correct 7 ms 492 KB Output is correct
27 Correct 6 ms 492 KB Output is correct
28 Correct 6 ms 492 KB Output is correct
29 Correct 7 ms 492 KB Output is correct
30 Correct 5 ms 364 KB Output is correct
31 Correct 6 ms 492 KB Output is correct
32 Correct 4 ms 492 KB Output is correct
33 Correct 6 ms 492 KB Output is correct
34 Correct 8 ms 492 KB Output is correct
35 Correct 6 ms 492 KB Output is correct
36 Correct 4 ms 492 KB Output is correct
37 Correct 30 ms 620 KB Output is correct
38 Correct 31 ms 748 KB Output is correct
39 Correct 80 ms 876 KB Output is correct
40 Correct 61 ms 876 KB Output is correct
41 Correct 103 ms 1004 KB Output is correct
42 Correct 51 ms 748 KB Output is correct
43 Correct 95 ms 1260 KB Output is correct
44 Correct 94 ms 1132 KB Output is correct
45 Correct 97 ms 1132 KB Output is correct
46 Correct 49 ms 620 KB Output is correct
47 Correct 55 ms 876 KB Output is correct
48 Correct 98 ms 1132 KB Output is correct
49 Correct 89 ms 904 KB Output is correct
50 Correct 56 ms 876 KB Output is correct
51 Correct 3 ms 492 KB Output is correct
52 Correct 124 ms 1276 KB Output is correct
53 Correct 97 ms 1044 KB Output is correct
54 Correct 132 ms 1260 KB Output is correct
55 Correct 254 ms 1904 KB Output is correct
56 Correct 116 ms 1152 KB Output is correct
57 Correct 281 ms 1904 KB Output is correct
58 Correct 143 ms 1260 KB Output is correct
59 Correct 181 ms 1520 KB Output is correct
60 Correct 6 ms 620 KB Output is correct
61 Correct 201 ms 1648 KB Output is correct
62 Correct 203 ms 1776 KB Output is correct
63 Correct 239 ms 1776 KB Output is correct
64 Correct 213 ms 1776 KB Output is correct
65 Correct 86 ms 748 KB Output is correct
66 Correct 90 ms 876 KB Output is correct
67 Correct 214 ms 1520 KB Output is correct
68 Correct 17 ms 876 KB Output is correct
69 Correct 708 ms 3252 KB Output is correct
70 Correct 440 ms 2288 KB Output is correct
71 Correct 428 ms 2176 KB Output is correct
72 Correct 412 ms 1516 KB Output is correct
73 Correct 406 ms 1388 KB Output is correct
74 Correct 744 ms 3692 KB Output is correct
75 Correct 576 ms 2924 KB Output is correct
76 Correct 799 ms 3564 KB Output is correct
77 Correct 783 ms 3692 KB Output is correct