답안 #464882

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
464882 2021-08-14T11:23:25 Z TeaTime Bootfall (IZhO17_bootfall) C++17
100 / 100
323 ms 83292 KB
//#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <bitset>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

#define int ll
const ll INF = 1e9, SZ = 510 * 510, SZ2 = 510;

ll n;
vector<ll> vec;
bitset<SZ> bts;
bitset<SZ> pref[SZ2], suf[SZ2], un[SZ2];
vector<ll> svd[SZ2 * 4];
bitset<SZ> cur[SZ2 * 4];

void psh(int v, int l, int r, int askl, int askr, int val) {
    if (askr <= askl) return;
    if (l >= askr || r <= askl) return;

    if (askl <= l && r <= askr) {
        svd[v].push_back(val);
        return;
    }

    int mid = (l + r) / 2;
    psh(v * 2 + 1, l, mid, askl, askr, val);
    psh(v * 2 + 2, mid, r, askl, askr, val);
}

void build(int v, int l, int r) {
    for (auto c : svd[v]) cur[v] |= (cur[v] << c);
    if (l == r - 1) {
        un[l] = cur[v];
    } else {
        int mid = (l + r) / 2;
        cur[v * 2 + 1] = cur[v];
        cur[v * 2 + 2] = cur[v];
        build(v * 2 + 1, l, mid);
        build(v * 2 + 2, mid, r);
    }
}
signed main() {
    fastInp;

    cin >> n;
    vec.resize(n);

    for (auto& c : vec) cin >> c;

    bts[0] = 1;
    ll sm = 0;

    pref[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        psh(0, 0, SZ2, 0, i - 1, vec[i - 1]);
        psh(0, 0, SZ2, i, SZ2, vec[i - 1]);
        pref[i] = (pref[i - 1] | (pref[i - 1] << vec[i - 1]));
    }

    suf[n][0] = 1;
    for (int i = n - 1; i >= 0; i--) {
        suf[i] = (suf[i + 1] | (suf[i + 1] << vec[i]));
    }

    cur[0][0] = 1;
    build(0, 0, SZ2);
   /* for (int i = n - 1; i >= 0; i--) {
        for (int j = 0; j < SZ; j++) {
            if (pref[i][j]) un[i] |= (suf[i + 1] << j);
        }
    }*/

    for (auto c : vec) {
        sm += c;
        bts |= (bts << c);
    }

    if (sm % 2) {
        cout << "0";
        return 0;
    }

    if (bts[sm / 2] != 1) {
        cout << "0";
        return 0;
    }

    vector<ll> ans;

    for (int i = 1; i < SZ; i++) {
        bool f = 1;
        for (int j = 0; j < n; j++) {
            ll cursm = sm - vec[j] + i;
            if (cursm % 2) {
                f = 0;
                break;
            }

            cursm /= 2;
            if (i > cursm) {
                f = 0;
                break;
            }

            if (!un[j][cursm - i]) {
                f = 0;
                break;
            }
        }

        if (f) ans.push_back(i);
    }

    cout << ans.size() << "\n";
    for (auto c : ans) cout << c << " ";
   
    return 0;
}

/*
3 4
RGWR
GRGG
RGWW

4 4
RGWR
GRRG
WGGW
WWWR

5 5
RGRGW
GRRGW
WGGWR
RWRGW
RGWGW
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 49860 KB Output is correct
2 Correct 24 ms 50044 KB Output is correct
3 Correct 22 ms 49832 KB Output is correct
4 Correct 23 ms 49920 KB Output is correct
5 Correct 32 ms 50348 KB Output is correct
6 Correct 24 ms 50196 KB Output is correct
7 Correct 26 ms 49996 KB Output is correct
8 Correct 25 ms 50428 KB Output is correct
9 Correct 26 ms 50264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 49860 KB Output is correct
2 Correct 24 ms 50044 KB Output is correct
3 Correct 22 ms 49832 KB Output is correct
4 Correct 23 ms 49920 KB Output is correct
5 Correct 32 ms 50348 KB Output is correct
6 Correct 24 ms 50196 KB Output is correct
7 Correct 26 ms 49996 KB Output is correct
8 Correct 25 ms 50428 KB Output is correct
9 Correct 26 ms 50264 KB Output is correct
10 Correct 30 ms 51592 KB Output is correct
11 Correct 28 ms 51568 KB Output is correct
12 Correct 28 ms 51532 KB Output is correct
13 Correct 27 ms 51200 KB Output is correct
14 Correct 28 ms 51352 KB Output is correct
15 Correct 27 ms 51384 KB Output is correct
16 Correct 28 ms 51520 KB Output is correct
17 Correct 26 ms 50764 KB Output is correct
18 Correct 26 ms 51176 KB Output is correct
19 Correct 27 ms 51276 KB Output is correct
20 Correct 27 ms 51508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 49860 KB Output is correct
2 Correct 24 ms 50044 KB Output is correct
3 Correct 22 ms 49832 KB Output is correct
4 Correct 23 ms 49920 KB Output is correct
5 Correct 32 ms 50348 KB Output is correct
6 Correct 24 ms 50196 KB Output is correct
7 Correct 26 ms 49996 KB Output is correct
8 Correct 25 ms 50428 KB Output is correct
9 Correct 26 ms 50264 KB Output is correct
10 Correct 30 ms 51592 KB Output is correct
11 Correct 28 ms 51568 KB Output is correct
12 Correct 28 ms 51532 KB Output is correct
13 Correct 27 ms 51200 KB Output is correct
14 Correct 28 ms 51352 KB Output is correct
15 Correct 27 ms 51384 KB Output is correct
16 Correct 28 ms 51520 KB Output is correct
17 Correct 26 ms 50764 KB Output is correct
18 Correct 26 ms 51176 KB Output is correct
19 Correct 27 ms 51276 KB Output is correct
20 Correct 27 ms 51508 KB Output is correct
21 Correct 35 ms 53812 KB Output is correct
22 Correct 34 ms 54424 KB Output is correct
23 Correct 31 ms 52912 KB Output is correct
24 Correct 37 ms 55756 KB Output is correct
25 Correct 38 ms 55704 KB Output is correct
26 Correct 39 ms 56076 KB Output is correct
27 Correct 43 ms 55992 KB Output is correct
28 Correct 38 ms 55980 KB Output is correct
29 Correct 38 ms 55964 KB Output is correct
30 Correct 38 ms 56008 KB Output is correct
31 Correct 39 ms 56120 KB Output is correct
32 Correct 39 ms 55988 KB Output is correct
33 Correct 39 ms 55992 KB Output is correct
34 Correct 39 ms 56004 KB Output is correct
35 Correct 38 ms 55944 KB Output is correct
36 Correct 39 ms 56112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 49860 KB Output is correct
2 Correct 24 ms 50044 KB Output is correct
3 Correct 22 ms 49832 KB Output is correct
4 Correct 23 ms 49920 KB Output is correct
5 Correct 32 ms 50348 KB Output is correct
6 Correct 24 ms 50196 KB Output is correct
7 Correct 26 ms 49996 KB Output is correct
8 Correct 25 ms 50428 KB Output is correct
9 Correct 26 ms 50264 KB Output is correct
10 Correct 30 ms 51592 KB Output is correct
11 Correct 28 ms 51568 KB Output is correct
12 Correct 28 ms 51532 KB Output is correct
13 Correct 27 ms 51200 KB Output is correct
14 Correct 28 ms 51352 KB Output is correct
15 Correct 27 ms 51384 KB Output is correct
16 Correct 28 ms 51520 KB Output is correct
17 Correct 26 ms 50764 KB Output is correct
18 Correct 26 ms 51176 KB Output is correct
19 Correct 27 ms 51276 KB Output is correct
20 Correct 27 ms 51508 KB Output is correct
21 Correct 35 ms 53812 KB Output is correct
22 Correct 34 ms 54424 KB Output is correct
23 Correct 31 ms 52912 KB Output is correct
24 Correct 37 ms 55756 KB Output is correct
25 Correct 38 ms 55704 KB Output is correct
26 Correct 39 ms 56076 KB Output is correct
27 Correct 43 ms 55992 KB Output is correct
28 Correct 38 ms 55980 KB Output is correct
29 Correct 38 ms 55964 KB Output is correct
30 Correct 38 ms 56008 KB Output is correct
31 Correct 39 ms 56120 KB Output is correct
32 Correct 39 ms 55988 KB Output is correct
33 Correct 39 ms 55992 KB Output is correct
34 Correct 39 ms 56004 KB Output is correct
35 Correct 38 ms 55944 KB Output is correct
36 Correct 39 ms 56112 KB Output is correct
37 Correct 60 ms 62668 KB Output is correct
38 Correct 61 ms 62664 KB Output is correct
39 Correct 61 ms 65384 KB Output is correct
40 Correct 78 ms 67144 KB Output is correct
41 Correct 62 ms 66764 KB Output is correct
42 Correct 73 ms 66056 KB Output is correct
43 Correct 82 ms 65608 KB Output is correct
44 Correct 87 ms 65872 KB Output is correct
45 Correct 86 ms 66000 KB Output is correct
46 Correct 67 ms 66772 KB Output is correct
47 Correct 74 ms 65860 KB Output is correct
48 Correct 77 ms 65936 KB Output is correct
49 Correct 65 ms 65632 KB Output is correct
50 Correct 76 ms 65880 KB Output is correct
51 Correct 60 ms 65740 KB Output is correct
52 Correct 92 ms 67352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 49860 KB Output is correct
2 Correct 24 ms 50044 KB Output is correct
3 Correct 22 ms 49832 KB Output is correct
4 Correct 23 ms 49920 KB Output is correct
5 Correct 32 ms 50348 KB Output is correct
6 Correct 24 ms 50196 KB Output is correct
7 Correct 26 ms 49996 KB Output is correct
8 Correct 25 ms 50428 KB Output is correct
9 Correct 26 ms 50264 KB Output is correct
10 Correct 30 ms 51592 KB Output is correct
11 Correct 28 ms 51568 KB Output is correct
12 Correct 28 ms 51532 KB Output is correct
13 Correct 27 ms 51200 KB Output is correct
14 Correct 28 ms 51352 KB Output is correct
15 Correct 27 ms 51384 KB Output is correct
16 Correct 28 ms 51520 KB Output is correct
17 Correct 26 ms 50764 KB Output is correct
18 Correct 26 ms 51176 KB Output is correct
19 Correct 27 ms 51276 KB Output is correct
20 Correct 27 ms 51508 KB Output is correct
21 Correct 35 ms 53812 KB Output is correct
22 Correct 34 ms 54424 KB Output is correct
23 Correct 31 ms 52912 KB Output is correct
24 Correct 37 ms 55756 KB Output is correct
25 Correct 38 ms 55704 KB Output is correct
26 Correct 39 ms 56076 KB Output is correct
27 Correct 43 ms 55992 KB Output is correct
28 Correct 38 ms 55980 KB Output is correct
29 Correct 38 ms 55964 KB Output is correct
30 Correct 38 ms 56008 KB Output is correct
31 Correct 39 ms 56120 KB Output is correct
32 Correct 39 ms 55988 KB Output is correct
33 Correct 39 ms 55992 KB Output is correct
34 Correct 39 ms 56004 KB Output is correct
35 Correct 38 ms 55944 KB Output is correct
36 Correct 39 ms 56112 KB Output is correct
37 Correct 60 ms 62668 KB Output is correct
38 Correct 61 ms 62664 KB Output is correct
39 Correct 61 ms 65384 KB Output is correct
40 Correct 78 ms 67144 KB Output is correct
41 Correct 62 ms 66764 KB Output is correct
42 Correct 73 ms 66056 KB Output is correct
43 Correct 82 ms 65608 KB Output is correct
44 Correct 87 ms 65872 KB Output is correct
45 Correct 86 ms 66000 KB Output is correct
46 Correct 67 ms 66772 KB Output is correct
47 Correct 74 ms 65860 KB Output is correct
48 Correct 77 ms 65936 KB Output is correct
49 Correct 65 ms 65632 KB Output is correct
50 Correct 76 ms 65880 KB Output is correct
51 Correct 60 ms 65740 KB Output is correct
52 Correct 92 ms 67352 KB Output is correct
53 Correct 94 ms 69208 KB Output is correct
54 Correct 116 ms 72488 KB Output is correct
55 Correct 150 ms 72696 KB Output is correct
56 Correct 102 ms 69604 KB Output is correct
57 Correct 148 ms 72860 KB Output is correct
58 Correct 113 ms 72512 KB Output is correct
59 Correct 127 ms 72624 KB Output is correct
60 Correct 73 ms 72132 KB Output is correct
61 Correct 130 ms 72596 KB Output is correct
62 Correct 126 ms 70780 KB Output is correct
63 Correct 130 ms 70844 KB Output is correct
64 Correct 127 ms 70420 KB Output is correct
65 Correct 71 ms 69820 KB Output is correct
66 Correct 75 ms 69572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 49860 KB Output is correct
2 Correct 24 ms 50044 KB Output is correct
3 Correct 22 ms 49832 KB Output is correct
4 Correct 23 ms 49920 KB Output is correct
5 Correct 32 ms 50348 KB Output is correct
6 Correct 24 ms 50196 KB Output is correct
7 Correct 26 ms 49996 KB Output is correct
8 Correct 25 ms 50428 KB Output is correct
9 Correct 26 ms 50264 KB Output is correct
10 Correct 30 ms 51592 KB Output is correct
11 Correct 28 ms 51568 KB Output is correct
12 Correct 28 ms 51532 KB Output is correct
13 Correct 27 ms 51200 KB Output is correct
14 Correct 28 ms 51352 KB Output is correct
15 Correct 27 ms 51384 KB Output is correct
16 Correct 28 ms 51520 KB Output is correct
17 Correct 26 ms 50764 KB Output is correct
18 Correct 26 ms 51176 KB Output is correct
19 Correct 27 ms 51276 KB Output is correct
20 Correct 27 ms 51508 KB Output is correct
21 Correct 35 ms 53812 KB Output is correct
22 Correct 34 ms 54424 KB Output is correct
23 Correct 31 ms 52912 KB Output is correct
24 Correct 37 ms 55756 KB Output is correct
25 Correct 38 ms 55704 KB Output is correct
26 Correct 39 ms 56076 KB Output is correct
27 Correct 43 ms 55992 KB Output is correct
28 Correct 38 ms 55980 KB Output is correct
29 Correct 38 ms 55964 KB Output is correct
30 Correct 38 ms 56008 KB Output is correct
31 Correct 39 ms 56120 KB Output is correct
32 Correct 39 ms 55988 KB Output is correct
33 Correct 39 ms 55992 KB Output is correct
34 Correct 39 ms 56004 KB Output is correct
35 Correct 38 ms 55944 KB Output is correct
36 Correct 39 ms 56112 KB Output is correct
37 Correct 60 ms 62668 KB Output is correct
38 Correct 61 ms 62664 KB Output is correct
39 Correct 61 ms 65384 KB Output is correct
40 Correct 78 ms 67144 KB Output is correct
41 Correct 62 ms 66764 KB Output is correct
42 Correct 73 ms 66056 KB Output is correct
43 Correct 82 ms 65608 KB Output is correct
44 Correct 87 ms 65872 KB Output is correct
45 Correct 86 ms 66000 KB Output is correct
46 Correct 67 ms 66772 KB Output is correct
47 Correct 74 ms 65860 KB Output is correct
48 Correct 77 ms 65936 KB Output is correct
49 Correct 65 ms 65632 KB Output is correct
50 Correct 76 ms 65880 KB Output is correct
51 Correct 60 ms 65740 KB Output is correct
52 Correct 92 ms 67352 KB Output is correct
53 Correct 94 ms 69208 KB Output is correct
54 Correct 116 ms 72488 KB Output is correct
55 Correct 150 ms 72696 KB Output is correct
56 Correct 102 ms 69604 KB Output is correct
57 Correct 148 ms 72860 KB Output is correct
58 Correct 113 ms 72512 KB Output is correct
59 Correct 127 ms 72624 KB Output is correct
60 Correct 73 ms 72132 KB Output is correct
61 Correct 130 ms 72596 KB Output is correct
62 Correct 126 ms 70780 KB Output is correct
63 Correct 130 ms 70844 KB Output is correct
64 Correct 127 ms 70420 KB Output is correct
65 Correct 71 ms 69820 KB Output is correct
66 Correct 75 ms 69572 KB Output is correct
67 Correct 143 ms 75832 KB Output is correct
68 Correct 95 ms 81604 KB Output is correct
69 Correct 287 ms 83044 KB Output is correct
70 Correct 215 ms 82620 KB Output is correct
71 Correct 216 ms 82464 KB Output is correct
72 Correct 93 ms 81476 KB Output is correct
73 Correct 92 ms 81404 KB Output is correct
74 Correct 312 ms 83048 KB Output is correct
75 Correct 262 ms 82824 KB Output is correct
76 Correct 292 ms 83252 KB Output is correct
77 Correct 323 ms 83292 KB Output is correct