답안 #671940

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
671940 2022-12-14T09:51:54 Z viwlesxq Bootfall (IZhO17_bootfall) C++17
100 / 100
237 ms 4352 KB
#include "bits/stdc++.h"
#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 string str;

#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
void freo(str x) {freopen((x + ".in").c_str(), "r", stdin);freopen((x + ".out").c_str(), "w", stdout);}

const int MAXN = 500, MAXSUM = 250001;
ll dp[MAXSUM];
int used[MAXSUM];
vector <int> ans;
 
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	int sum = 0, a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	dp[0]++;
	if (sum % 2) {
		cout << 0;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		for (int j = sum; j - a[i] >= 0; j--) {
			dp[j] += dp[j - a[i]];
		}
	}
	if (!dp[sum / 2]) {
		cout << 0;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		int cur = sum - a[i];
		for (int j = a[i]; j <= sum; j++) {
			dp[j] -= dp[j - a[i]];
		}
		for (int j = 0; j <= cur / 2; j++) {
			if (dp[j]) used[cur - j * 2]++;
		}
		for (int j = sum; j >= a[i]; j--) {
			dp[j] += dp[j - a[i]];
		}
	}
	for (int i = 0; i <= sum; i++) {
		if (used[i] == n) ans.pb(i);
	}
	cout << sz(ans) << '\n';
	for (int i : ans) cout << i << ' ';
}

Compilation message

bootfall.cpp: In function 'void freo(str)':
bootfall.cpp:21:26: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 | void freo(str x) {freopen((x + ".in").c_str(), "r", stdin);freopen((x + ".out").c_str(), "w", stdout);}
      |                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:21:67: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 | void freo(str x) {freopen((x + ".in").c_str(), "r", stdin);freopen((x + ".out").c_str(), "w", stdout);}
      |                                                            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 388 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 2 ms 448 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 388 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 2 ms 448 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 8 ms 724 KB Output is correct
38 Correct 9 ms 724 KB Output is correct
39 Correct 30 ms 1056 KB Output is correct
40 Correct 18 ms 852 KB Output is correct
41 Correct 36 ms 1108 KB Output is correct
42 Correct 19 ms 820 KB Output is correct
43 Correct 31 ms 1220 KB Output is correct
44 Correct 28 ms 1364 KB Output is correct
45 Correct 29 ms 1284 KB Output is correct
46 Correct 17 ms 596 KB Output is correct
47 Correct 16 ms 840 KB Output is correct
48 Correct 31 ms 1300 KB Output is correct
49 Correct 33 ms 1100 KB Output is correct
50 Correct 17 ms 920 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 40 ms 1532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 388 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 2 ms 448 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 8 ms 724 KB Output is correct
38 Correct 9 ms 724 KB Output is correct
39 Correct 30 ms 1056 KB Output is correct
40 Correct 18 ms 852 KB Output is correct
41 Correct 36 ms 1108 KB Output is correct
42 Correct 19 ms 820 KB Output is correct
43 Correct 31 ms 1220 KB Output is correct
44 Correct 28 ms 1364 KB Output is correct
45 Correct 29 ms 1284 KB Output is correct
46 Correct 17 ms 596 KB Output is correct
47 Correct 16 ms 840 KB Output is correct
48 Correct 31 ms 1300 KB Output is correct
49 Correct 33 ms 1100 KB Output is correct
50 Correct 17 ms 920 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 40 ms 1532 KB Output is correct
53 Correct 27 ms 1100 KB Output is correct
54 Correct 38 ms 1360 KB Output is correct
55 Correct 85 ms 2224 KB Output is correct
56 Correct 34 ms 1364 KB Output is correct
57 Correct 84 ms 2384 KB Output is correct
58 Correct 43 ms 1356 KB Output is correct
59 Correct 52 ms 1596 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 63 ms 1828 KB Output is correct
62 Correct 64 ms 1952 KB Output is correct
63 Correct 79 ms 2044 KB Output is correct
64 Correct 63 ms 2132 KB Output is correct
65 Correct 31 ms 904 KB Output is correct
66 Correct 32 ms 1004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 388 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 3 ms 468 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 2 ms 448 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 8 ms 724 KB Output is correct
38 Correct 9 ms 724 KB Output is correct
39 Correct 30 ms 1056 KB Output is correct
40 Correct 18 ms 852 KB Output is correct
41 Correct 36 ms 1108 KB Output is correct
42 Correct 19 ms 820 KB Output is correct
43 Correct 31 ms 1220 KB Output is correct
44 Correct 28 ms 1364 KB Output is correct
45 Correct 29 ms 1284 KB Output is correct
46 Correct 17 ms 596 KB Output is correct
47 Correct 16 ms 840 KB Output is correct
48 Correct 31 ms 1300 KB Output is correct
49 Correct 33 ms 1100 KB Output is correct
50 Correct 17 ms 920 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 40 ms 1532 KB Output is correct
53 Correct 27 ms 1100 KB Output is correct
54 Correct 38 ms 1360 KB Output is correct
55 Correct 85 ms 2224 KB Output is correct
56 Correct 34 ms 1364 KB Output is correct
57 Correct 84 ms 2384 KB Output is correct
58 Correct 43 ms 1356 KB Output is correct
59 Correct 52 ms 1596 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 63 ms 1828 KB Output is correct
62 Correct 64 ms 1952 KB Output is correct
63 Correct 79 ms 2044 KB Output is correct
64 Correct 63 ms 2132 KB Output is correct
65 Correct 31 ms 904 KB Output is correct
66 Correct 32 ms 1004 KB Output is correct
67 Correct 63 ms 1724 KB Output is correct
68 Correct 35 ms 1280 KB Output is correct
69 Correct 208 ms 3948 KB Output is correct
70 Correct 123 ms 2596 KB Output is correct
71 Correct 115 ms 2544 KB Output is correct
72 Correct 112 ms 1692 KB Output is correct
73 Correct 111 ms 1684 KB Output is correct
74 Correct 224 ms 4092 KB Output is correct
75 Correct 176 ms 3356 KB Output is correct
76 Correct 235 ms 4288 KB Output is correct
77 Correct 237 ms 4352 KB Output is correct