답안 #502815

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
502815 2022-01-06T15:38:08 Z tox1c_kid Bootfall (IZhO17_bootfall) C++17
100 / 100
850 ms 4340 KB
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdio>
#include <sstream>
#include <cassert>
#include <vector>
#include <numeric>
#include <string>
#include <bitset>
#include <cmath>
#include <complex>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
#include <ctime>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>

/*
 ⠄⠄⠄⢰⣧⣼⣯⠄⣸⣠⣶⣶⣦⣾⠄⠄⠄⠄⡀⠄⢀⣿⣿⠄⠄⠄⢸⡇⠄⠄
⠄⠄⠄⣾⣿⠿⠿⠶⠿⢿⣿⣿⣿⣿⣦⣤⣄⢀⡅⢠⣾⣛⡉⠄⠄⠄⠸⢀⣿⠄
⠄⠄⢀⡋⣡⣴⣶⣶⡀⠄⠄⠙⢿⣿⣿⣿⣿⣿⣴⣿⣿⣿⢃⣤⣄⣀⣥⣿⣿⠄
⠄⠄⢸⣇⠻⣿⣿⣿⣧⣀⢀⣠⡌⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠿⠿⣿⣿⣿⠄
⠄⢀⢸⣿⣷⣤⣤⣤⣬⣙⣛⢿⣿⣿⣿⣿⣿⣿⡿⣿⣿⡍⠄⠄⢀⣤⣄⠉⠋⣰
⠄⣼⣖⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⣿⣿⣿⣿⣿⢇⣿⣿⡷⠶⠶⢿⣿⣿⠇⢀⣤
⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⣿⣿⣿⣿⣿⣿⣷⣶⣥⣴⣿⡗
⢀⠈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠄
⢸⣿⣦⣌⣛⣻⣿⣿⣧⠙⠛⠛⡭⠅⠒⠦⠭⣭⡻⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠄
⠘⣿⣿⣿⣿⣿⣿⣿⣿⡆⠄⠄⠄⠄⠄⠄⠄⠄⠹⠈⢋⣽⣿⣿⣿⣿⣵⣾⠃⠄
⠄⠘⣿⣿⣿⣿⣿⣿⣿⣿⠄⣴⣿⣶⣄⠄⣴⣶⠄⢀⣾⣿⣿⣿⣿⣿⣿⠃⠄⠄
⠄⠄⠈⠻⣿⣿⣿⣿⣿⣿⡄⢻⣿⣿⣿⠄⣿⣿⡀⣾⣿⣿⣿⣿⣛⠛⠁⠄⠄⠄
⠄⠄⠄⠄⠈⠛⢿⣿⣿⣿⠁⠞⢿⣿⣿⡄⢿⣿⡇⣸⣿⣿⠿⠛⠁⠄⠄⠄⠄⠄
⠄⠄⠄⠄⠄⠄⠄⠉⠻⣿⣿⣾⣦⡙⠻⣷⣾⣿⠃⠿⠋⠁⠄⠄⠄⠄⠄⢀⣠⣴
⣿⣿⣿⣶⣶⣮⣥⣒⠲⢮⣝⡿⣿⣿⡆⣿⡿⠃⠄⠄⠄⠄⠄⠄⠄⣠⣴⣿⣿⣿
 */

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define all(x) (x).begin(), (x).end()
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cout << "\n"; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << " " << to_string(H);
    debug_out(T...);
}

#ifdef CLOWN
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__);
#else
#define dbg(...);
#endif

int test = 0;

void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> ans;

    int sum = accumulate(all(a), 0);

    vector<int> dp(sum + 1);
    dp[0] = 1;

    for (int i =0 ; i < n;i++) {
        for (int j = sum; j >= 0; j--) {
            if (j + a[i] <= sum) {
                dp[j + a[i]] += dp[j];
            }
        }
    }
    if (sum % 2 || !dp[sum / 2]) {
        cout << 0 << "\n";
        return;
    }
    vector<int> used(sum * 2);
    for (int i = 0; i < n; i++) {
        for (int j = a[i]; j <= sum ; j++) {
            dp[j ] -= dp[j - a[i]];
        }

        for (int j = (sum - a[i]) / 2; j <= sum; j++) {
            int cur = 2 * j - sum + a[i];
            dbg(cur);
            if (cur > 0 && dp[j]) used[cur]++;
        }
        for (int j = sum; j >= a[i]; j--) {
                dp[j] += dp[j - a[i]];
        }
    }
    dbg(used)
    for (int i = 1; i < sum * 2 ; i++) {
        if (used[i] == n) {
            ans.push_back(i);
        }
    }
    cout << ans.size() << "\n";
    for (auto i : ans) cout << i << " ";
}

int32_t main() {
#ifdef CLOWN
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    fastio();
    if (test) cin >> t;
    while (t--) { solve(); }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 268 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 268 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 0 ms 316 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 268 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 0 ms 316 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 316 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 4 ms 316 KB Output is correct
25 Correct 6 ms 444 KB Output is correct
26 Correct 7 ms 460 KB Output is correct
27 Correct 6 ms 332 KB Output is correct
28 Correct 6 ms 332 KB Output is correct
29 Correct 6 ms 332 KB Output is correct
30 Correct 4 ms 332 KB Output is correct
31 Correct 6 ms 448 KB Output is correct
32 Correct 4 ms 332 KB Output is correct
33 Correct 7 ms 316 KB Output is correct
34 Correct 6 ms 332 KB Output is correct
35 Correct 6 ms 432 KB Output is correct
36 Correct 4 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 268 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 0 ms 316 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 316 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 4 ms 316 KB Output is correct
25 Correct 6 ms 444 KB Output is correct
26 Correct 7 ms 460 KB Output is correct
27 Correct 6 ms 332 KB Output is correct
28 Correct 6 ms 332 KB Output is correct
29 Correct 6 ms 332 KB Output is correct
30 Correct 4 ms 332 KB Output is correct
31 Correct 6 ms 448 KB Output is correct
32 Correct 4 ms 332 KB Output is correct
33 Correct 7 ms 316 KB Output is correct
34 Correct 6 ms 332 KB Output is correct
35 Correct 6 ms 432 KB Output is correct
36 Correct 4 ms 316 KB Output is correct
37 Correct 21 ms 672 KB Output is correct
38 Correct 19 ms 692 KB Output is correct
39 Correct 88 ms 936 KB Output is correct
40 Correct 57 ms 816 KB Output is correct
41 Correct 84 ms 1172 KB Output is correct
42 Correct 52 ms 792 KB Output is correct
43 Correct 96 ms 1432 KB Output is correct
44 Correct 89 ms 1292 KB Output is correct
45 Correct 90 ms 1368 KB Output is correct
46 Correct 49 ms 560 KB Output is correct
47 Correct 56 ms 840 KB Output is correct
48 Correct 103 ms 1316 KB Output is correct
49 Correct 92 ms 1036 KB Output is correct
50 Correct 62 ms 824 KB Output is correct
51 Correct 26 ms 332 KB Output is correct
52 Correct 141 ms 1516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 268 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 0 ms 316 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 316 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 4 ms 316 KB Output is correct
25 Correct 6 ms 444 KB Output is correct
26 Correct 7 ms 460 KB Output is correct
27 Correct 6 ms 332 KB Output is correct
28 Correct 6 ms 332 KB Output is correct
29 Correct 6 ms 332 KB Output is correct
30 Correct 4 ms 332 KB Output is correct
31 Correct 6 ms 448 KB Output is correct
32 Correct 4 ms 332 KB Output is correct
33 Correct 7 ms 316 KB Output is correct
34 Correct 6 ms 332 KB Output is correct
35 Correct 6 ms 432 KB Output is correct
36 Correct 4 ms 316 KB Output is correct
37 Correct 21 ms 672 KB Output is correct
38 Correct 19 ms 692 KB Output is correct
39 Correct 88 ms 936 KB Output is correct
40 Correct 57 ms 816 KB Output is correct
41 Correct 84 ms 1172 KB Output is correct
42 Correct 52 ms 792 KB Output is correct
43 Correct 96 ms 1432 KB Output is correct
44 Correct 89 ms 1292 KB Output is correct
45 Correct 90 ms 1368 KB Output is correct
46 Correct 49 ms 560 KB Output is correct
47 Correct 56 ms 840 KB Output is correct
48 Correct 103 ms 1316 KB Output is correct
49 Correct 92 ms 1036 KB Output is correct
50 Correct 62 ms 824 KB Output is correct
51 Correct 26 ms 332 KB Output is correct
52 Correct 141 ms 1516 KB Output is correct
53 Correct 118 ms 1132 KB Output is correct
54 Correct 136 ms 1348 KB Output is correct
55 Correct 246 ms 2160 KB Output is correct
56 Correct 138 ms 1352 KB Output is correct
57 Correct 252 ms 2312 KB Output is correct
58 Correct 135 ms 1416 KB Output is correct
59 Correct 185 ms 1596 KB Output is correct
60 Correct 67 ms 460 KB Output is correct
61 Correct 184 ms 1828 KB Output is correct
62 Correct 189 ms 1948 KB Output is correct
63 Correct 223 ms 2136 KB Output is correct
64 Correct 203 ms 2028 KB Output is correct
65 Correct 85 ms 872 KB Output is correct
66 Correct 86 ms 896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 268 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 0 ms 316 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 316 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 316 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 4 ms 316 KB Output is correct
25 Correct 6 ms 444 KB Output is correct
26 Correct 7 ms 460 KB Output is correct
27 Correct 6 ms 332 KB Output is correct
28 Correct 6 ms 332 KB Output is correct
29 Correct 6 ms 332 KB Output is correct
30 Correct 4 ms 332 KB Output is correct
31 Correct 6 ms 448 KB Output is correct
32 Correct 4 ms 332 KB Output is correct
33 Correct 7 ms 316 KB Output is correct
34 Correct 6 ms 332 KB Output is correct
35 Correct 6 ms 432 KB Output is correct
36 Correct 4 ms 316 KB Output is correct
37 Correct 21 ms 672 KB Output is correct
38 Correct 19 ms 692 KB Output is correct
39 Correct 88 ms 936 KB Output is correct
40 Correct 57 ms 816 KB Output is correct
41 Correct 84 ms 1172 KB Output is correct
42 Correct 52 ms 792 KB Output is correct
43 Correct 96 ms 1432 KB Output is correct
44 Correct 89 ms 1292 KB Output is correct
45 Correct 90 ms 1368 KB Output is correct
46 Correct 49 ms 560 KB Output is correct
47 Correct 56 ms 840 KB Output is correct
48 Correct 103 ms 1316 KB Output is correct
49 Correct 92 ms 1036 KB Output is correct
50 Correct 62 ms 824 KB Output is correct
51 Correct 26 ms 332 KB Output is correct
52 Correct 141 ms 1516 KB Output is correct
53 Correct 118 ms 1132 KB Output is correct
54 Correct 136 ms 1348 KB Output is correct
55 Correct 246 ms 2160 KB Output is correct
56 Correct 138 ms 1352 KB Output is correct
57 Correct 252 ms 2312 KB Output is correct
58 Correct 135 ms 1416 KB Output is correct
59 Correct 185 ms 1596 KB Output is correct
60 Correct 67 ms 460 KB Output is correct
61 Correct 184 ms 1828 KB Output is correct
62 Correct 189 ms 1948 KB Output is correct
63 Correct 223 ms 2136 KB Output is correct
64 Correct 203 ms 2028 KB Output is correct
65 Correct 85 ms 872 KB Output is correct
66 Correct 86 ms 896 KB Output is correct
67 Correct 209 ms 1776 KB Output is correct
68 Correct 191 ms 716 KB Output is correct
69 Correct 677 ms 3944 KB Output is correct
70 Correct 404 ms 2476 KB Output is correct
71 Correct 399 ms 2412 KB Output is correct
72 Correct 367 ms 1788 KB Output is correct
73 Correct 410 ms 1776 KB Output is correct
74 Correct 710 ms 4092 KB Output is correct
75 Correct 573 ms 3424 KB Output is correct
76 Correct 850 ms 4340 KB Output is correct
77 Correct 802 ms 4300 KB Output is correct