답안 #682476

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
682476 2023-01-16T09:20:10 Z iskhakkutbilim Bootfall (IZhO17_bootfall) C++14
100 / 100
792 ms 7768 KB
#include <bits/stdc++.h>
using namespace std;

//#define int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int N = 500;
const int S =2*500 * 500;
int dp[S+1];
main(){
	int n; cin >> n;
	vector<int> a(n);
	int sum = 0, even = 0, odd = 0;
	for(int i = 0;i < n; i++){
		cin >> a[i];
		odd+= (a[i]%2==1);
		even+= (a[i]%2==0);
		sum+= a[i];
	}
	dp[0] = 1;
	for(int i = 0;i < n; i++){
		for(int s = sum; s >= a[i]; s--){
			dp[s] += dp[s-a[i]];
		}
	}
	if((even > 0 and odd > 0) or sum%2 or !dp[sum/2]){
		cout << 0;
		return 0;
	}
	set<int> can;
	for(int tima = 1; tima <= sum; tima++){
		sum+= tima;
		int ok = 1;
		for(int i = 0;i < a.size(); i++){
			if((sum-a[i])%2==1){
				ok = 0;
				break;
			}
		}
		if(ok) can.insert(tima);
		sum-= tima;
	}
	for(int i = 0;i < n; i++){
		for(int s = a[i]; s <= sum; s++){
			dp[s]-= dp[s - a[i]];
		}
		vector<int> del;
		for(int tima : can){
			if(!dp[(sum-a[i]+tima) / 2]) del.push_back(tima);
		}
		for(int x : del) can.erase(x);
		for(int s = sum; s >= a[i]; s--) dp[s]+= dp[s-a[i]];
	}
	cout << can.size() << '\n';
	for(int x : can) cout << x << ' ';
	return 0;
}

Compilation message

bootfall.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main(){
      | ^~~~
bootfall.cpp: In function 'int main()':
bootfall.cpp:35:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for(int i = 0;i < a.size(); i++){
      |                 ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 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 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 5 ms 468 KB Output is correct
26 Correct 6 ms 468 KB Output is correct
27 Correct 5 ms 568 KB Output is correct
28 Correct 5 ms 468 KB Output is correct
29 Correct 5 ms 596 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 5 ms 468 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 5 ms 596 KB Output is correct
34 Correct 4 ms 596 KB Output is correct
35 Correct 5 ms 596 KB Output is correct
36 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 5 ms 468 KB Output is correct
26 Correct 6 ms 468 KB Output is correct
27 Correct 5 ms 568 KB Output is correct
28 Correct 5 ms 468 KB Output is correct
29 Correct 5 ms 596 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 5 ms 468 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 5 ms 596 KB Output is correct
34 Correct 4 ms 596 KB Output is correct
35 Correct 5 ms 596 KB Output is correct
36 Correct 3 ms 340 KB Output is correct
37 Correct 26 ms 836 KB Output is correct
38 Correct 28 ms 844 KB Output is correct
39 Correct 53 ms 2204 KB Output is correct
40 Correct 51 ms 1228 KB Output is correct
41 Correct 66 ms 2636 KB Output is correct
42 Correct 51 ms 1124 KB Output is correct
43 Correct 76 ms 1944 KB Output is correct
44 Correct 92 ms 2092 KB Output is correct
45 Correct 98 ms 1928 KB Output is correct
46 Correct 30 ms 1216 KB Output is correct
47 Correct 57 ms 1184 KB Output is correct
48 Correct 85 ms 2032 KB Output is correct
49 Correct 60 ms 2132 KB Output is correct
50 Correct 54 ms 1228 KB Output is correct
51 Correct 7 ms 468 KB Output is correct
52 Correct 101 ms 2376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 5 ms 468 KB Output is correct
26 Correct 6 ms 468 KB Output is correct
27 Correct 5 ms 568 KB Output is correct
28 Correct 5 ms 468 KB Output is correct
29 Correct 5 ms 596 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 5 ms 468 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 5 ms 596 KB Output is correct
34 Correct 4 ms 596 KB Output is correct
35 Correct 5 ms 596 KB Output is correct
36 Correct 3 ms 340 KB Output is correct
37 Correct 26 ms 836 KB Output is correct
38 Correct 28 ms 844 KB Output is correct
39 Correct 53 ms 2204 KB Output is correct
40 Correct 51 ms 1228 KB Output is correct
41 Correct 66 ms 2636 KB Output is correct
42 Correct 51 ms 1124 KB Output is correct
43 Correct 76 ms 1944 KB Output is correct
44 Correct 92 ms 2092 KB Output is correct
45 Correct 98 ms 1928 KB Output is correct
46 Correct 30 ms 1216 KB Output is correct
47 Correct 57 ms 1184 KB Output is correct
48 Correct 85 ms 2032 KB Output is correct
49 Correct 60 ms 2132 KB Output is correct
50 Correct 54 ms 1228 KB Output is correct
51 Correct 7 ms 468 KB Output is correct
52 Correct 101 ms 2376 KB Output is correct
53 Correct 78 ms 1552 KB Output is correct
54 Correct 109 ms 1940 KB Output is correct
55 Correct 210 ms 3640 KB Output is correct
56 Correct 101 ms 1968 KB Output is correct
57 Correct 219 ms 3764 KB Output is correct
58 Correct 122 ms 2100 KB Output is correct
59 Correct 153 ms 2524 KB Output is correct
60 Correct 17 ms 544 KB Output is correct
61 Correct 171 ms 2768 KB Output is correct
62 Correct 180 ms 3280 KB Output is correct
63 Correct 197 ms 3412 KB Output is correct
64 Correct 202 ms 3404 KB Output is correct
65 Correct 55 ms 1732 KB Output is correct
66 Correct 71 ms 1940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 5 ms 468 KB Output is correct
26 Correct 6 ms 468 KB Output is correct
27 Correct 5 ms 568 KB Output is correct
28 Correct 5 ms 468 KB Output is correct
29 Correct 5 ms 596 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 5 ms 468 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 5 ms 596 KB Output is correct
34 Correct 4 ms 596 KB Output is correct
35 Correct 5 ms 596 KB Output is correct
36 Correct 3 ms 340 KB Output is correct
37 Correct 26 ms 836 KB Output is correct
38 Correct 28 ms 844 KB Output is correct
39 Correct 53 ms 2204 KB Output is correct
40 Correct 51 ms 1228 KB Output is correct
41 Correct 66 ms 2636 KB Output is correct
42 Correct 51 ms 1124 KB Output is correct
43 Correct 76 ms 1944 KB Output is correct
44 Correct 92 ms 2092 KB Output is correct
45 Correct 98 ms 1928 KB Output is correct
46 Correct 30 ms 1216 KB Output is correct
47 Correct 57 ms 1184 KB Output is correct
48 Correct 85 ms 2032 KB Output is correct
49 Correct 60 ms 2132 KB Output is correct
50 Correct 54 ms 1228 KB Output is correct
51 Correct 7 ms 468 KB Output is correct
52 Correct 101 ms 2376 KB Output is correct
53 Correct 78 ms 1552 KB Output is correct
54 Correct 109 ms 1940 KB Output is correct
55 Correct 210 ms 3640 KB Output is correct
56 Correct 101 ms 1968 KB Output is correct
57 Correct 219 ms 3764 KB Output is correct
58 Correct 122 ms 2100 KB Output is correct
59 Correct 153 ms 2524 KB Output is correct
60 Correct 17 ms 544 KB Output is correct
61 Correct 171 ms 2768 KB Output is correct
62 Correct 180 ms 3280 KB Output is correct
63 Correct 197 ms 3412 KB Output is correct
64 Correct 202 ms 3404 KB Output is correct
65 Correct 55 ms 1732 KB Output is correct
66 Correct 71 ms 1940 KB Output is correct
67 Correct 189 ms 2696 KB Output is correct
68 Correct 47 ms 724 KB Output is correct
69 Correct 629 ms 6872 KB Output is correct
70 Correct 374 ms 4192 KB Output is correct
71 Correct 366 ms 3944 KB Output is correct
72 Correct 48 ms 724 KB Output is correct
73 Correct 50 ms 692 KB Output is correct
74 Correct 792 ms 7092 KB Output is correct
75 Correct 500 ms 5576 KB Output is correct
76 Correct 704 ms 7768 KB Output is correct
77 Correct 708 ms 7500 KB Output is correct