답안 #925218

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925218 2024-02-11T05:10:08 Z atom Bootfall (IZhO17_bootfall) C++17
100 / 100
573 ms 6612 KB
#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;

#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif

const int N = 501 * 501;
const int MOD = 1e9 + 7;
int n;
int a[N];

signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    
    #ifdef JASPER
        freopen("in1", "r", stdin);
    #endif

    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];

    int sz = accumulate(a + 1, a + 1 + n, 0);
	
	// dp(x) : number of ways constructing sum equal to x;
	vector <ll> dp1(N, 0), dp2(N, 0);
	vector <int> able(N, 1);
	dp1[0] = 1;

	// solving first case: a[0] is the observer
	// -> use first case to solve others
	for (int i = 1; i <= n; ++i) 
		for (int j = sz; j >= a[i]; --j)
			(dp1[j] += dp1[j - a[i]]) %= MOD;

	if ((sz & 1) || !dp1[sz / 2]) {
		cout << "0\n";
		return 0;
	}


	auto solve = [&] (int id) -> void {
		for (int i = 0; i < N; ++i) dp2[i] = dp1[i];
		// remove a(id) from current set
		for (int j = a[id]; j < N; ++j)
			(dp2[j] += MOD - dp2[j - a[id]]) %= MOD;
		// choose value
		for (int x = 1; x < N; ++x) {
			int new_sz = sz - a[id] + x;
			if ((new_sz & 1) || (new_sz / 2 - x < 0) || !dp2[(new_sz / 2) - x])
				able[x] = 0;
		}
	};
	

	for (int i = 1; i <= n; ++i) {
		// debug(able[3]);
		solve(i);
	}

	vector <int> ans;
	for (int x = 1; x < N; ++x) {
		if (able[x]) {
			ans.push_back(x);
		}
	}

	cout << (int) (ans.size()) << "\n";
	for (int x : ans) cout << x << " ";
}

# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 5212 KB Output is correct
2 Correct 7 ms 5212 KB Output is correct
3 Correct 2 ms 5464 KB Output is correct
4 Correct 6 ms 5212 KB Output is correct
5 Correct 12 ms 5396 KB Output is correct
6 Correct 9 ms 5212 KB Output is correct
7 Correct 7 ms 5280 KB Output is correct
8 Correct 12 ms 5212 KB Output is correct
9 Correct 10 ms 5208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 5212 KB Output is correct
2 Correct 7 ms 5212 KB Output is correct
3 Correct 2 ms 5464 KB Output is correct
4 Correct 6 ms 5212 KB Output is correct
5 Correct 12 ms 5396 KB Output is correct
6 Correct 9 ms 5212 KB Output is correct
7 Correct 7 ms 5280 KB Output is correct
8 Correct 12 ms 5212 KB Output is correct
9 Correct 10 ms 5208 KB Output is correct
10 Correct 26 ms 5212 KB Output is correct
11 Correct 30 ms 5212 KB Output is correct
12 Correct 26 ms 5212 KB Output is correct
13 Correct 25 ms 5208 KB Output is correct
14 Correct 25 ms 5208 KB Output is correct
15 Correct 28 ms 5208 KB Output is correct
16 Correct 32 ms 5212 KB Output is correct
17 Correct 18 ms 5212 KB Output is correct
18 Correct 26 ms 5208 KB Output is correct
19 Correct 25 ms 5212 KB Output is correct
20 Correct 25 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 5212 KB Output is correct
2 Correct 7 ms 5212 KB Output is correct
3 Correct 2 ms 5464 KB Output is correct
4 Correct 6 ms 5212 KB Output is correct
5 Correct 12 ms 5396 KB Output is correct
6 Correct 9 ms 5212 KB Output is correct
7 Correct 7 ms 5280 KB Output is correct
8 Correct 12 ms 5212 KB Output is correct
9 Correct 10 ms 5208 KB Output is correct
10 Correct 26 ms 5212 KB Output is correct
11 Correct 30 ms 5212 KB Output is correct
12 Correct 26 ms 5212 KB Output is correct
13 Correct 25 ms 5208 KB Output is correct
14 Correct 25 ms 5208 KB Output is correct
15 Correct 28 ms 5208 KB Output is correct
16 Correct 32 ms 5212 KB Output is correct
17 Correct 18 ms 5212 KB Output is correct
18 Correct 26 ms 5208 KB Output is correct
19 Correct 25 ms 5212 KB Output is correct
20 Correct 25 ms 5212 KB Output is correct
21 Correct 52 ms 5212 KB Output is correct
22 Correct 60 ms 5208 KB Output is correct
23 Correct 43 ms 5388 KB Output is correct
24 Correct 78 ms 5372 KB Output is correct
25 Correct 76 ms 5388 KB Output is correct
26 Correct 90 ms 5396 KB Output is correct
27 Correct 78 ms 5372 KB Output is correct
28 Correct 79 ms 5212 KB Output is correct
29 Correct 79 ms 5384 KB Output is correct
30 Correct 79 ms 5208 KB Output is correct
31 Correct 82 ms 5552 KB Output is correct
32 Correct 79 ms 5212 KB Output is correct
33 Correct 79 ms 5212 KB Output is correct
34 Correct 79 ms 5208 KB Output is correct
35 Correct 80 ms 5208 KB Output is correct
36 Correct 81 ms 5372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 5212 KB Output is correct
2 Correct 7 ms 5212 KB Output is correct
3 Correct 2 ms 5464 KB Output is correct
4 Correct 6 ms 5212 KB Output is correct
5 Correct 12 ms 5396 KB Output is correct
6 Correct 9 ms 5212 KB Output is correct
7 Correct 7 ms 5280 KB Output is correct
8 Correct 12 ms 5212 KB Output is correct
9 Correct 10 ms 5208 KB Output is correct
10 Correct 26 ms 5212 KB Output is correct
11 Correct 30 ms 5212 KB Output is correct
12 Correct 26 ms 5212 KB Output is correct
13 Correct 25 ms 5208 KB Output is correct
14 Correct 25 ms 5208 KB Output is correct
15 Correct 28 ms 5208 KB Output is correct
16 Correct 32 ms 5212 KB Output is correct
17 Correct 18 ms 5212 KB Output is correct
18 Correct 26 ms 5208 KB Output is correct
19 Correct 25 ms 5212 KB Output is correct
20 Correct 25 ms 5212 KB Output is correct
21 Correct 52 ms 5212 KB Output is correct
22 Correct 60 ms 5208 KB Output is correct
23 Correct 43 ms 5388 KB Output is correct
24 Correct 78 ms 5372 KB Output is correct
25 Correct 76 ms 5388 KB Output is correct
26 Correct 90 ms 5396 KB Output is correct
27 Correct 78 ms 5372 KB Output is correct
28 Correct 79 ms 5212 KB Output is correct
29 Correct 79 ms 5384 KB Output is correct
30 Correct 79 ms 5208 KB Output is correct
31 Correct 82 ms 5552 KB Output is correct
32 Correct 79 ms 5212 KB Output is correct
33 Correct 79 ms 5212 KB Output is correct
34 Correct 79 ms 5208 KB Output is correct
35 Correct 80 ms 5208 KB Output is correct
36 Correct 81 ms 5372 KB Output is correct
37 Correct 160 ms 5456 KB Output is correct
38 Correct 156 ms 5376 KB Output is correct
39 Correct 219 ms 5460 KB Output is correct
40 Correct 215 ms 5456 KB Output is correct
41 Correct 232 ms 5208 KB Output is correct
42 Correct 200 ms 5376 KB Output is correct
43 Correct 209 ms 5644 KB Output is correct
44 Correct 210 ms 5716 KB Output is correct
45 Correct 216 ms 5716 KB Output is correct
46 Correct 237 ms 5372 KB Output is correct
47 Correct 209 ms 5460 KB Output is correct
48 Correct 217 ms 5632 KB Output is correct
49 Correct 217 ms 5376 KB Output is correct
50 Correct 212 ms 5372 KB Output is correct
51 Correct 12 ms 5212 KB Output is correct
52 Correct 245 ms 5716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 5212 KB Output is correct
2 Correct 7 ms 5212 KB Output is correct
3 Correct 2 ms 5464 KB Output is correct
4 Correct 6 ms 5212 KB Output is correct
5 Correct 12 ms 5396 KB Output is correct
6 Correct 9 ms 5212 KB Output is correct
7 Correct 7 ms 5280 KB Output is correct
8 Correct 12 ms 5212 KB Output is correct
9 Correct 10 ms 5208 KB Output is correct
10 Correct 26 ms 5212 KB Output is correct
11 Correct 30 ms 5212 KB Output is correct
12 Correct 26 ms 5212 KB Output is correct
13 Correct 25 ms 5208 KB Output is correct
14 Correct 25 ms 5208 KB Output is correct
15 Correct 28 ms 5208 KB Output is correct
16 Correct 32 ms 5212 KB Output is correct
17 Correct 18 ms 5212 KB Output is correct
18 Correct 26 ms 5208 KB Output is correct
19 Correct 25 ms 5212 KB Output is correct
20 Correct 25 ms 5212 KB Output is correct
21 Correct 52 ms 5212 KB Output is correct
22 Correct 60 ms 5208 KB Output is correct
23 Correct 43 ms 5388 KB Output is correct
24 Correct 78 ms 5372 KB Output is correct
25 Correct 76 ms 5388 KB Output is correct
26 Correct 90 ms 5396 KB Output is correct
27 Correct 78 ms 5372 KB Output is correct
28 Correct 79 ms 5212 KB Output is correct
29 Correct 79 ms 5384 KB Output is correct
30 Correct 79 ms 5208 KB Output is correct
31 Correct 82 ms 5552 KB Output is correct
32 Correct 79 ms 5212 KB Output is correct
33 Correct 79 ms 5212 KB Output is correct
34 Correct 79 ms 5208 KB Output is correct
35 Correct 80 ms 5208 KB Output is correct
36 Correct 81 ms 5372 KB Output is correct
37 Correct 160 ms 5456 KB Output is correct
38 Correct 156 ms 5376 KB Output is correct
39 Correct 219 ms 5460 KB Output is correct
40 Correct 215 ms 5456 KB Output is correct
41 Correct 232 ms 5208 KB Output is correct
42 Correct 200 ms 5376 KB Output is correct
43 Correct 209 ms 5644 KB Output is correct
44 Correct 210 ms 5716 KB Output is correct
45 Correct 216 ms 5716 KB Output is correct
46 Correct 237 ms 5372 KB Output is correct
47 Correct 209 ms 5460 KB Output is correct
48 Correct 217 ms 5632 KB Output is correct
49 Correct 217 ms 5376 KB Output is correct
50 Correct 212 ms 5372 KB Output is correct
51 Correct 12 ms 5212 KB Output is correct
52 Correct 245 ms 5716 KB Output is correct
53 Correct 247 ms 5644 KB Output is correct
54 Correct 291 ms 5628 KB Output is correct
55 Correct 350 ms 5764 KB Output is correct
56 Correct 255 ms 5624 KB Output is correct
57 Correct 336 ms 6020 KB Output is correct
58 Correct 302 ms 5636 KB Output is correct
59 Correct 302 ms 5760 KB Output is correct
60 Correct 30 ms 5212 KB Output is correct
61 Correct 315 ms 5764 KB Output is correct
62 Correct 291 ms 5764 KB Output is correct
63 Correct 300 ms 5756 KB Output is correct
64 Correct 303 ms 5844 KB Output is correct
65 Correct 267 ms 5368 KB Output is correct
66 Correct 259 ms 5460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 5212 KB Output is correct
2 Correct 7 ms 5212 KB Output is correct
3 Correct 2 ms 5464 KB Output is correct
4 Correct 6 ms 5212 KB Output is correct
5 Correct 12 ms 5396 KB Output is correct
6 Correct 9 ms 5212 KB Output is correct
7 Correct 7 ms 5280 KB Output is correct
8 Correct 12 ms 5212 KB Output is correct
9 Correct 10 ms 5208 KB Output is correct
10 Correct 26 ms 5212 KB Output is correct
11 Correct 30 ms 5212 KB Output is correct
12 Correct 26 ms 5212 KB Output is correct
13 Correct 25 ms 5208 KB Output is correct
14 Correct 25 ms 5208 KB Output is correct
15 Correct 28 ms 5208 KB Output is correct
16 Correct 32 ms 5212 KB Output is correct
17 Correct 18 ms 5212 KB Output is correct
18 Correct 26 ms 5208 KB Output is correct
19 Correct 25 ms 5212 KB Output is correct
20 Correct 25 ms 5212 KB Output is correct
21 Correct 52 ms 5212 KB Output is correct
22 Correct 60 ms 5208 KB Output is correct
23 Correct 43 ms 5388 KB Output is correct
24 Correct 78 ms 5372 KB Output is correct
25 Correct 76 ms 5388 KB Output is correct
26 Correct 90 ms 5396 KB Output is correct
27 Correct 78 ms 5372 KB Output is correct
28 Correct 79 ms 5212 KB Output is correct
29 Correct 79 ms 5384 KB Output is correct
30 Correct 79 ms 5208 KB Output is correct
31 Correct 82 ms 5552 KB Output is correct
32 Correct 79 ms 5212 KB Output is correct
33 Correct 79 ms 5212 KB Output is correct
34 Correct 79 ms 5208 KB Output is correct
35 Correct 80 ms 5208 KB Output is correct
36 Correct 81 ms 5372 KB Output is correct
37 Correct 160 ms 5456 KB Output is correct
38 Correct 156 ms 5376 KB Output is correct
39 Correct 219 ms 5460 KB Output is correct
40 Correct 215 ms 5456 KB Output is correct
41 Correct 232 ms 5208 KB Output is correct
42 Correct 200 ms 5376 KB Output is correct
43 Correct 209 ms 5644 KB Output is correct
44 Correct 210 ms 5716 KB Output is correct
45 Correct 216 ms 5716 KB Output is correct
46 Correct 237 ms 5372 KB Output is correct
47 Correct 209 ms 5460 KB Output is correct
48 Correct 217 ms 5632 KB Output is correct
49 Correct 217 ms 5376 KB Output is correct
50 Correct 212 ms 5372 KB Output is correct
51 Correct 12 ms 5212 KB Output is correct
52 Correct 245 ms 5716 KB Output is correct
53 Correct 247 ms 5644 KB Output is correct
54 Correct 291 ms 5628 KB Output is correct
55 Correct 350 ms 5764 KB Output is correct
56 Correct 255 ms 5624 KB Output is correct
57 Correct 336 ms 6020 KB Output is correct
58 Correct 302 ms 5636 KB Output is correct
59 Correct 302 ms 5760 KB Output is correct
60 Correct 30 ms 5212 KB Output is correct
61 Correct 315 ms 5764 KB Output is correct
62 Correct 291 ms 5764 KB Output is correct
63 Correct 300 ms 5756 KB Output is correct
64 Correct 303 ms 5844 KB Output is correct
65 Correct 267 ms 5368 KB Output is correct
66 Correct 259 ms 5460 KB Output is correct
67 Correct 355 ms 5764 KB Output is correct
68 Correct 80 ms 5212 KB Output is correct
69 Correct 545 ms 6528 KB Output is correct
70 Correct 479 ms 6016 KB Output is correct
71 Correct 481 ms 6016 KB Output is correct
72 Correct 468 ms 5372 KB Output is correct
73 Correct 475 ms 5212 KB Output is correct
74 Correct 556 ms 6524 KB Output is correct
75 Correct 514 ms 6356 KB Output is correct
76 Correct 573 ms 6520 KB Output is correct
77 Correct 567 ms 6612 KB Output is correct