답안 #672417

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
672417 2022-12-16T03:26:57 Z Baytoro Bootfall (IZhO17_bootfall) C++17
100 / 100
600 ms 4328 KB
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define int long long
//#define endl '\n'
void fopn(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const int INF=1e18,mod=998244353;
const int N=3e5;
int dp[N+5];
int sum=0;
void add(int x){
	for(int i=N;i>=x;i--){
		dp[i]+=dp[i-x];
	}
}
void remove(int x){
	for(int i=x;i<=N;i++){
		dp[i]-=dp[i-x];
	}
}
int n;
void solve(){
	int n;
	cin>>n;
	vector<int> vec(n);
	dp[0]=1;
	for(int i=0;i<n;i++){
		cin>>vec[i];
		sum+=vec[i];
		add(vec[i]);
	}
	if(sum%2 || !dp[sum/2]){
		cout<<0<<endl;
		return;
	}
	vector<bool> used(N+5,1);
	for(int i=0;i<n;i++){
		remove(vec[i]);
		for(int j=1;j<=N;j++){
			if(!used[j]) continue;
			if((sum-vec[i]+j)%2 || !dp[(sum-vec[i]+j)/2]){
				used[j]=0;
			}
		}
		add(vec[i]);
	}
	vector<int> ans;
	for(int i=1;i<=N;i++){
		if(used[i]) ans.pb(i);
	}
	cout<<ans.size()<<endl;
	for(auto it: ans)
		cout<<it<<' ';
}
main(){
	//ios;
	int T=1;
	//cin>>T;
	while(T--){
		solve();
	}
}

Compilation message

bootfall.cpp:63:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   63 | main(){
      | ^~~~
bootfall.cpp: In function 'void fopn(std::string)':
bootfall.cpp:12:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2688 KB Output is correct
2 Correct 9 ms 2564 KB Output is correct
3 Correct 3 ms 2616 KB Output is correct
4 Correct 8 ms 2612 KB Output is correct
5 Correct 15 ms 2644 KB Output is correct
6 Correct 10 ms 2656 KB Output is correct
7 Correct 8 ms 2644 KB Output is correct
8 Correct 13 ms 2644 KB Output is correct
9 Correct 12 ms 2684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2688 KB Output is correct
2 Correct 9 ms 2564 KB Output is correct
3 Correct 3 ms 2616 KB Output is correct
4 Correct 8 ms 2612 KB Output is correct
5 Correct 15 ms 2644 KB Output is correct
6 Correct 10 ms 2656 KB Output is correct
7 Correct 8 ms 2644 KB Output is correct
8 Correct 13 ms 2644 KB Output is correct
9 Correct 12 ms 2684 KB Output is correct
10 Correct 33 ms 2644 KB Output is correct
11 Correct 33 ms 2648 KB Output is correct
12 Correct 30 ms 2644 KB Output is correct
13 Correct 27 ms 2772 KB Output is correct
14 Correct 32 ms 2644 KB Output is correct
15 Correct 29 ms 2660 KB Output is correct
16 Correct 37 ms 2668 KB Output is correct
17 Correct 21 ms 2644 KB Output is correct
18 Correct 25 ms 2644 KB Output is correct
19 Correct 29 ms 2652 KB Output is correct
20 Correct 29 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2688 KB Output is correct
2 Correct 9 ms 2564 KB Output is correct
3 Correct 3 ms 2616 KB Output is correct
4 Correct 8 ms 2612 KB Output is correct
5 Correct 15 ms 2644 KB Output is correct
6 Correct 10 ms 2656 KB Output is correct
7 Correct 8 ms 2644 KB Output is correct
8 Correct 13 ms 2644 KB Output is correct
9 Correct 12 ms 2684 KB Output is correct
10 Correct 33 ms 2644 KB Output is correct
11 Correct 33 ms 2648 KB Output is correct
12 Correct 30 ms 2644 KB Output is correct
13 Correct 27 ms 2772 KB Output is correct
14 Correct 32 ms 2644 KB Output is correct
15 Correct 29 ms 2660 KB Output is correct
16 Correct 37 ms 2668 KB Output is correct
17 Correct 21 ms 2644 KB Output is correct
18 Correct 25 ms 2644 KB Output is correct
19 Correct 29 ms 2652 KB Output is correct
20 Correct 29 ms 2644 KB Output is correct
21 Correct 61 ms 2664 KB Output is correct
22 Correct 86 ms 2668 KB Output is correct
23 Correct 48 ms 2680 KB Output is correct
24 Correct 112 ms 2664 KB Output is correct
25 Correct 89 ms 2644 KB Output is correct
26 Correct 91 ms 2644 KB Output is correct
27 Correct 108 ms 2644 KB Output is correct
28 Correct 113 ms 2664 KB Output is correct
29 Correct 95 ms 2668 KB Output is correct
30 Correct 92 ms 2656 KB Output is correct
31 Correct 90 ms 2644 KB Output is correct
32 Correct 92 ms 2664 KB Output is correct
33 Correct 90 ms 2664 KB Output is correct
34 Correct 93 ms 2644 KB Output is correct
35 Correct 93 ms 2668 KB Output is correct
36 Correct 95 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2688 KB Output is correct
2 Correct 9 ms 2564 KB Output is correct
3 Correct 3 ms 2616 KB Output is correct
4 Correct 8 ms 2612 KB Output is correct
5 Correct 15 ms 2644 KB Output is correct
6 Correct 10 ms 2656 KB Output is correct
7 Correct 8 ms 2644 KB Output is correct
8 Correct 13 ms 2644 KB Output is correct
9 Correct 12 ms 2684 KB Output is correct
10 Correct 33 ms 2644 KB Output is correct
11 Correct 33 ms 2648 KB Output is correct
12 Correct 30 ms 2644 KB Output is correct
13 Correct 27 ms 2772 KB Output is correct
14 Correct 32 ms 2644 KB Output is correct
15 Correct 29 ms 2660 KB Output is correct
16 Correct 37 ms 2668 KB Output is correct
17 Correct 21 ms 2644 KB Output is correct
18 Correct 25 ms 2644 KB Output is correct
19 Correct 29 ms 2652 KB Output is correct
20 Correct 29 ms 2644 KB Output is correct
21 Correct 61 ms 2664 KB Output is correct
22 Correct 86 ms 2668 KB Output is correct
23 Correct 48 ms 2680 KB Output is correct
24 Correct 112 ms 2664 KB Output is correct
25 Correct 89 ms 2644 KB Output is correct
26 Correct 91 ms 2644 KB Output is correct
27 Correct 108 ms 2644 KB Output is correct
28 Correct 113 ms 2664 KB Output is correct
29 Correct 95 ms 2668 KB Output is correct
30 Correct 92 ms 2656 KB Output is correct
31 Correct 90 ms 2644 KB Output is correct
32 Correct 92 ms 2664 KB Output is correct
33 Correct 90 ms 2664 KB Output is correct
34 Correct 93 ms 2644 KB Output is correct
35 Correct 93 ms 2668 KB Output is correct
36 Correct 95 ms 2648 KB Output is correct
37 Correct 213 ms 2940 KB Output is correct
38 Correct 183 ms 2928 KB Output is correct
39 Correct 227 ms 2636 KB Output is correct
40 Correct 265 ms 2928 KB Output is correct
41 Correct 258 ms 2672 KB Output is correct
42 Correct 224 ms 2988 KB Output is correct
43 Correct 243 ms 3136 KB Output is correct
44 Correct 271 ms 3152 KB Output is correct
45 Correct 239 ms 3056 KB Output is correct
46 Correct 253 ms 2800 KB Output is correct
47 Correct 226 ms 2932 KB Output is correct
48 Correct 276 ms 3016 KB Output is correct
49 Correct 224 ms 2764 KB Output is correct
50 Correct 237 ms 2928 KB Output is correct
51 Correct 55 ms 2644 KB Output is correct
52 Correct 305 ms 3180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2688 KB Output is correct
2 Correct 9 ms 2564 KB Output is correct
3 Correct 3 ms 2616 KB Output is correct
4 Correct 8 ms 2612 KB Output is correct
5 Correct 15 ms 2644 KB Output is correct
6 Correct 10 ms 2656 KB Output is correct
7 Correct 8 ms 2644 KB Output is correct
8 Correct 13 ms 2644 KB Output is correct
9 Correct 12 ms 2684 KB Output is correct
10 Correct 33 ms 2644 KB Output is correct
11 Correct 33 ms 2648 KB Output is correct
12 Correct 30 ms 2644 KB Output is correct
13 Correct 27 ms 2772 KB Output is correct
14 Correct 32 ms 2644 KB Output is correct
15 Correct 29 ms 2660 KB Output is correct
16 Correct 37 ms 2668 KB Output is correct
17 Correct 21 ms 2644 KB Output is correct
18 Correct 25 ms 2644 KB Output is correct
19 Correct 29 ms 2652 KB Output is correct
20 Correct 29 ms 2644 KB Output is correct
21 Correct 61 ms 2664 KB Output is correct
22 Correct 86 ms 2668 KB Output is correct
23 Correct 48 ms 2680 KB Output is correct
24 Correct 112 ms 2664 KB Output is correct
25 Correct 89 ms 2644 KB Output is correct
26 Correct 91 ms 2644 KB Output is correct
27 Correct 108 ms 2644 KB Output is correct
28 Correct 113 ms 2664 KB Output is correct
29 Correct 95 ms 2668 KB Output is correct
30 Correct 92 ms 2656 KB Output is correct
31 Correct 90 ms 2644 KB Output is correct
32 Correct 92 ms 2664 KB Output is correct
33 Correct 90 ms 2664 KB Output is correct
34 Correct 93 ms 2644 KB Output is correct
35 Correct 93 ms 2668 KB Output is correct
36 Correct 95 ms 2648 KB Output is correct
37 Correct 213 ms 2940 KB Output is correct
38 Correct 183 ms 2928 KB Output is correct
39 Correct 227 ms 2636 KB Output is correct
40 Correct 265 ms 2928 KB Output is correct
41 Correct 258 ms 2672 KB Output is correct
42 Correct 224 ms 2988 KB Output is correct
43 Correct 243 ms 3136 KB Output is correct
44 Correct 271 ms 3152 KB Output is correct
45 Correct 239 ms 3056 KB Output is correct
46 Correct 253 ms 2800 KB Output is correct
47 Correct 226 ms 2932 KB Output is correct
48 Correct 276 ms 3016 KB Output is correct
49 Correct 224 ms 2764 KB Output is correct
50 Correct 237 ms 2928 KB Output is correct
51 Correct 55 ms 2644 KB Output is correct
52 Correct 305 ms 3180 KB Output is correct
53 Correct 272 ms 3060 KB Output is correct
54 Correct 351 ms 3268 KB Output is correct
55 Correct 335 ms 3432 KB Output is correct
56 Correct 285 ms 3148 KB Output is correct
57 Correct 331 ms 3432 KB Output is correct
58 Correct 398 ms 3140 KB Output is correct
59 Correct 341 ms 3304 KB Output is correct
60 Correct 97 ms 2632 KB Output is correct
61 Correct 350 ms 3312 KB Output is correct
62 Correct 345 ms 3396 KB Output is correct
63 Correct 302 ms 3536 KB Output is correct
64 Correct 306 ms 3432 KB Output is correct
65 Correct 281 ms 2668 KB Output is correct
66 Correct 311 ms 2796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2688 KB Output is correct
2 Correct 9 ms 2564 KB Output is correct
3 Correct 3 ms 2616 KB Output is correct
4 Correct 8 ms 2612 KB Output is correct
5 Correct 15 ms 2644 KB Output is correct
6 Correct 10 ms 2656 KB Output is correct
7 Correct 8 ms 2644 KB Output is correct
8 Correct 13 ms 2644 KB Output is correct
9 Correct 12 ms 2684 KB Output is correct
10 Correct 33 ms 2644 KB Output is correct
11 Correct 33 ms 2648 KB Output is correct
12 Correct 30 ms 2644 KB Output is correct
13 Correct 27 ms 2772 KB Output is correct
14 Correct 32 ms 2644 KB Output is correct
15 Correct 29 ms 2660 KB Output is correct
16 Correct 37 ms 2668 KB Output is correct
17 Correct 21 ms 2644 KB Output is correct
18 Correct 25 ms 2644 KB Output is correct
19 Correct 29 ms 2652 KB Output is correct
20 Correct 29 ms 2644 KB Output is correct
21 Correct 61 ms 2664 KB Output is correct
22 Correct 86 ms 2668 KB Output is correct
23 Correct 48 ms 2680 KB Output is correct
24 Correct 112 ms 2664 KB Output is correct
25 Correct 89 ms 2644 KB Output is correct
26 Correct 91 ms 2644 KB Output is correct
27 Correct 108 ms 2644 KB Output is correct
28 Correct 113 ms 2664 KB Output is correct
29 Correct 95 ms 2668 KB Output is correct
30 Correct 92 ms 2656 KB Output is correct
31 Correct 90 ms 2644 KB Output is correct
32 Correct 92 ms 2664 KB Output is correct
33 Correct 90 ms 2664 KB Output is correct
34 Correct 93 ms 2644 KB Output is correct
35 Correct 93 ms 2668 KB Output is correct
36 Correct 95 ms 2648 KB Output is correct
37 Correct 213 ms 2940 KB Output is correct
38 Correct 183 ms 2928 KB Output is correct
39 Correct 227 ms 2636 KB Output is correct
40 Correct 265 ms 2928 KB Output is correct
41 Correct 258 ms 2672 KB Output is correct
42 Correct 224 ms 2988 KB Output is correct
43 Correct 243 ms 3136 KB Output is correct
44 Correct 271 ms 3152 KB Output is correct
45 Correct 239 ms 3056 KB Output is correct
46 Correct 253 ms 2800 KB Output is correct
47 Correct 226 ms 2932 KB Output is correct
48 Correct 276 ms 3016 KB Output is correct
49 Correct 224 ms 2764 KB Output is correct
50 Correct 237 ms 2928 KB Output is correct
51 Correct 55 ms 2644 KB Output is correct
52 Correct 305 ms 3180 KB Output is correct
53 Correct 272 ms 3060 KB Output is correct
54 Correct 351 ms 3268 KB Output is correct
55 Correct 335 ms 3432 KB Output is correct
56 Correct 285 ms 3148 KB Output is correct
57 Correct 331 ms 3432 KB Output is correct
58 Correct 398 ms 3140 KB Output is correct
59 Correct 341 ms 3304 KB Output is correct
60 Correct 97 ms 2632 KB Output is correct
61 Correct 350 ms 3312 KB Output is correct
62 Correct 345 ms 3396 KB Output is correct
63 Correct 302 ms 3536 KB Output is correct
64 Correct 306 ms 3432 KB Output is correct
65 Correct 281 ms 2668 KB Output is correct
66 Correct 311 ms 2796 KB Output is correct
67 Correct 390 ms 3304 KB Output is correct
68 Correct 112 ms 2644 KB Output is correct
69 Correct 522 ms 4196 KB Output is correct
70 Correct 496 ms 3680 KB Output is correct
71 Correct 479 ms 3652 KB Output is correct
72 Correct 442 ms 2764 KB Output is correct
73 Correct 446 ms 2776 KB Output is correct
74 Correct 500 ms 4328 KB Output is correct
75 Correct 506 ms 3936 KB Output is correct
76 Correct 600 ms 4200 KB Output is correct
77 Correct 511 ms 4324 KB Output is correct