답안 #1097711

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1097711 2024-10-08T04:04:03 Z anhthi Bootfall (IZhO17_bootfall) C++14
100 / 100
373 ms 3388 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define ll long long
#define mp(x, y) make_pair(x, y)
#define sz(v) ((int) (v).size())
#define all(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define BIT(x, y) (((x) >> (y)) & 1)
#define pb push_back
#define max_rng *max_element
#define min_rng *min_element
#define rep(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define forn(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define ford(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
 
template <class X, class Y>
    inline bool maximize(X &x, Y y) {
        return (x < y ? x = y, true : false);
    }
 
template <class X, class Y>
    inline bool minimize(X &x, Y y) {
        return (x > y ? x = y, true : false);
    }
 
template <class X>
    inline void compress(vector<X> &a) {
        sort(all(a));
        a.resize(unique(all(a)) - a.begin());
    }
 
int ctz(ll x) { return __builtin_ctzll(x); }
int lg(ll x) { return 63 - __builtin_clzll(x); }
int popcount(ll x) { return __builtin_popcount(x); }
 
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) {
    return l + abs((ll) rng()) % (r - l + 1);
}
 
const ll oo = (ll) 1e17;
const int inf = (ll) 1e9 + 7, mod = (ll) 1e9 + 7;
 
const int N = 5e2 + 5, M = 250005, BASE = 307, LOG = 23;
 
void add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
void sub(int &x, int y) { x -= y; if (x < 0) x += mod; }

int n;
int a[N];

int f[M];

int main(void) {
 
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    cin >> n;
    rep(i, n) cin >> a[i];

    int sum = accumulate(a + 1, a + 1 + n, 0);


    f[0] = 1;
    rep(i, n) ford(s, sum, a[i]) {
        add(f[s], f[s - a[i]]);
    }

    if (sum & 1 || !f[sum / 2]) return cout << 0, 0;
    
    vector<int> valid;
    rep(i, sum) valid.pb(i);

    rep(ban, n) {
        forn(s, a[ban], sum) sub(f[s], f[s - a[ban]]);

        vector<int> lst;
        for (int val : valid) {
            int res = sum - a[ban] + val;
            if (res & 1) continue;
            res >>= 1;
            if (f[res] > 0) {
                lst.pb(val);
            }
        }
        valid.swap(lst);

        ford(s, sum, a[ban]) add(f[s], f[s - a[ban]]);
    }
    cout << sz(valid) << '\n';
    for (int v : valid) cout << v << ' ';


    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 432 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 372 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 432 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 372 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 3 ms 604 KB Output is correct
26 Correct 3 ms 600 KB Output is correct
27 Correct 3 ms 600 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 3 ms 604 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 3 ms 348 KB Output is correct
32 Correct 2 ms 436 KB Output is correct
33 Correct 3 ms 856 KB Output is correct
34 Correct 3 ms 604 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 432 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 372 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 3 ms 604 KB Output is correct
26 Correct 3 ms 600 KB Output is correct
27 Correct 3 ms 600 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 3 ms 604 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 3 ms 348 KB Output is correct
32 Correct 2 ms 436 KB Output is correct
33 Correct 3 ms 856 KB Output is correct
34 Correct 3 ms 604 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 14 ms 604 KB Output is correct
38 Correct 14 ms 604 KB Output is correct
39 Correct 31 ms 1244 KB Output is correct
40 Correct 28 ms 852 KB Output is correct
41 Correct 42 ms 1248 KB Output is correct
42 Correct 25 ms 840 KB Output is correct
43 Correct 42 ms 996 KB Output is correct
44 Correct 43 ms 1168 KB Output is correct
45 Correct 44 ms 1028 KB Output is correct
46 Correct 19 ms 600 KB Output is correct
47 Correct 26 ms 852 KB Output is correct
48 Correct 44 ms 1008 KB Output is correct
49 Correct 35 ms 992 KB Output is correct
50 Correct 26 ms 860 KB Output is correct
51 Correct 9 ms 348 KB Output is correct
52 Correct 70 ms 1380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 432 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 372 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 3 ms 604 KB Output is correct
26 Correct 3 ms 600 KB Output is correct
27 Correct 3 ms 600 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 3 ms 604 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 3 ms 348 KB Output is correct
32 Correct 2 ms 436 KB Output is correct
33 Correct 3 ms 856 KB Output is correct
34 Correct 3 ms 604 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 14 ms 604 KB Output is correct
38 Correct 14 ms 604 KB Output is correct
39 Correct 31 ms 1244 KB Output is correct
40 Correct 28 ms 852 KB Output is correct
41 Correct 42 ms 1248 KB Output is correct
42 Correct 25 ms 840 KB Output is correct
43 Correct 42 ms 996 KB Output is correct
44 Correct 43 ms 1168 KB Output is correct
45 Correct 44 ms 1028 KB Output is correct
46 Correct 19 ms 600 KB Output is correct
47 Correct 26 ms 852 KB Output is correct
48 Correct 44 ms 1008 KB Output is correct
49 Correct 35 ms 992 KB Output is correct
50 Correct 26 ms 860 KB Output is correct
51 Correct 9 ms 348 KB Output is correct
52 Correct 70 ms 1380 KB Output is correct
53 Correct 45 ms 992 KB Output is correct
54 Correct 61 ms 1152 KB Output is correct
55 Correct 121 ms 1812 KB Output is correct
56 Correct 55 ms 1148 KB Output is correct
57 Correct 123 ms 1856 KB Output is correct
58 Correct 68 ms 1076 KB Output is correct
59 Correct 96 ms 1396 KB Output is correct
60 Correct 19 ms 604 KB Output is correct
61 Correct 102 ms 1496 KB Output is correct
62 Correct 101 ms 1700 KB Output is correct
63 Correct 108 ms 1744 KB Output is correct
64 Correct 110 ms 1596 KB Output is correct
65 Correct 31 ms 860 KB Output is correct
66 Correct 39 ms 992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 432 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 372 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 3 ms 604 KB Output is correct
26 Correct 3 ms 600 KB Output is correct
27 Correct 3 ms 600 KB Output is correct
28 Correct 3 ms 604 KB Output is correct
29 Correct 3 ms 604 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 3 ms 348 KB Output is correct
32 Correct 2 ms 436 KB Output is correct
33 Correct 3 ms 856 KB Output is correct
34 Correct 3 ms 604 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 14 ms 604 KB Output is correct
38 Correct 14 ms 604 KB Output is correct
39 Correct 31 ms 1244 KB Output is correct
40 Correct 28 ms 852 KB Output is correct
41 Correct 42 ms 1248 KB Output is correct
42 Correct 25 ms 840 KB Output is correct
43 Correct 42 ms 996 KB Output is correct
44 Correct 43 ms 1168 KB Output is correct
45 Correct 44 ms 1028 KB Output is correct
46 Correct 19 ms 600 KB Output is correct
47 Correct 26 ms 852 KB Output is correct
48 Correct 44 ms 1008 KB Output is correct
49 Correct 35 ms 992 KB Output is correct
50 Correct 26 ms 860 KB Output is correct
51 Correct 9 ms 348 KB Output is correct
52 Correct 70 ms 1380 KB Output is correct
53 Correct 45 ms 992 KB Output is correct
54 Correct 61 ms 1152 KB Output is correct
55 Correct 121 ms 1812 KB Output is correct
56 Correct 55 ms 1148 KB Output is correct
57 Correct 123 ms 1856 KB Output is correct
58 Correct 68 ms 1076 KB Output is correct
59 Correct 96 ms 1396 KB Output is correct
60 Correct 19 ms 604 KB Output is correct
61 Correct 102 ms 1496 KB Output is correct
62 Correct 101 ms 1700 KB Output is correct
63 Correct 108 ms 1744 KB Output is correct
64 Correct 110 ms 1596 KB Output is correct
65 Correct 31 ms 860 KB Output is correct
66 Correct 39 ms 992 KB Output is correct
67 Correct 109 ms 1500 KB Output is correct
68 Correct 42 ms 860 KB Output is correct
69 Correct 343 ms 3200 KB Output is correct
70 Correct 199 ms 1996 KB Output is correct
71 Correct 192 ms 1836 KB Output is correct
72 Correct 138 ms 1744 KB Output is correct
73 Correct 123 ms 1840 KB Output is correct
74 Correct 373 ms 3364 KB Output is correct
75 Correct 293 ms 2836 KB Output is correct
76 Correct 367 ms 3332 KB Output is correct
77 Correct 370 ms 3388 KB Output is correct