Submission #923028

# Submission time Handle Problem Language Result Execution time Memory
923028 2024-02-06T12:56:36 Z penguin133 Bootfall (IZhO17_bootfall) C++17
44 / 100
1000 ms 18264 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

bitset <271*271*2>dp[505], dp2[505];
int n, A[505];
const int os = 270 * 270;

bool chk(int a, int b){
	if(os - a - b >= 0 && dp[n & 1][os - a - b])return 1;
	if(os - a + b >= 0 && os - a + b <= 2 * os && dp[n & 1][os - a + b])return 1;
	if(os + a - b >= 0 && os + a - b <= 2 * os && dp[n & 1][os + a - b])return 1;
	if(os + a + b <= 2 * os && dp[n & 1][os + a + b])return 1;
	return 0;
}

void solve(){
	cin >> n;
	for(int i = 1; i <= n; i++)cin >> A[i];
	//for(int i = 0; i <= 2 * os; i++)dp[0][i] = 0
	dp[0][os] = dp2[n + 1][os] = 1;
	for(int i = 1; i <= n; i++){
		dp[i] |= (dp[i - 1] >> A[i]);
		dp[i] |= (dp[i - 1] << A[i]);
	}
	for(int i = n; i >= 1; i--){
		dp2[i] |= (dp2[i + 1] >> A[i]);
		dp2[i] |= (dp2[i + 1] << A[i]);
	}
	if(!dp[n][os]){
		cout << 0;
		return;
	}
	set <int> s;
	for(int i = 1; i <= os; i++)s.insert(i);
	for(int i = 1; i <= n; i++){
		/*
		bitset <501*501*2> tmp = dp[i - 1], tmp2;
		for(int j = 0; j <= os; j++){
			if(dp2[i + 1][os - j] || dp2[i + 1][os + j]){
				if(1)tmp2 |= (tmp >> j), tmp2 |= (tmp << j);
			}
		}
		*/
		bitset <271 * 271 * 2> tmp;
		tmp[os] = 1;
		for(int j = 1; j <= n; j++){
			if(j == i)continue;
			tmp = (tmp >> A[j]) | (tmp << A[j]);
		}
		for(int j = 0; j <= os; j++)if(!tmp[os - j] && !tmp[os + j])s.erase(j);
	}
	cout << (int)s.size() << '\n';
	for(auto i : s)cout << i << ' ';
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

Compilation message

bootfall.cpp:66:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   66 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 5976 KB Output is correct
2 Correct 14 ms 5976 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 14 ms 5980 KB Output is correct
5 Correct 22 ms 8028 KB Output is correct
6 Correct 15 ms 5976 KB Output is correct
7 Correct 14 ms 6132 KB Output is correct
8 Correct 19 ms 8028 KB Output is correct
9 Correct 18 ms 8028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 5976 KB Output is correct
2 Correct 14 ms 5976 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 14 ms 5980 KB Output is correct
5 Correct 22 ms 8028 KB Output is correct
6 Correct 15 ms 5976 KB Output is correct
7 Correct 14 ms 6132 KB Output is correct
8 Correct 19 ms 8028 KB Output is correct
9 Correct 18 ms 8028 KB Output is correct
10 Correct 28 ms 8028 KB Output is correct
11 Correct 30 ms 8028 KB Output is correct
12 Correct 28 ms 8024 KB Output is correct
13 Correct 25 ms 8028 KB Output is correct
14 Correct 32 ms 8028 KB Output is correct
15 Correct 28 ms 8028 KB Output is correct
16 Correct 30 ms 8280 KB Output is correct
17 Correct 22 ms 8028 KB Output is correct
18 Correct 26 ms 8208 KB Output is correct
19 Correct 28 ms 8028 KB Output is correct
20 Correct 26 ms 8060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 5976 KB Output is correct
2 Correct 14 ms 5976 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 14 ms 5980 KB Output is correct
5 Correct 22 ms 8028 KB Output is correct
6 Correct 15 ms 5976 KB Output is correct
7 Correct 14 ms 6132 KB Output is correct
8 Correct 19 ms 8028 KB Output is correct
9 Correct 18 ms 8028 KB Output is correct
10 Correct 28 ms 8028 KB Output is correct
11 Correct 30 ms 8028 KB Output is correct
12 Correct 28 ms 8024 KB Output is correct
13 Correct 25 ms 8028 KB Output is correct
14 Correct 32 ms 8028 KB Output is correct
15 Correct 28 ms 8028 KB Output is correct
16 Correct 30 ms 8280 KB Output is correct
17 Correct 22 ms 8028 KB Output is correct
18 Correct 26 ms 8208 KB Output is correct
19 Correct 28 ms 8028 KB Output is correct
20 Correct 26 ms 8060 KB Output is correct
21 Correct 75 ms 8028 KB Output is correct
22 Correct 87 ms 8028 KB Output is correct
23 Correct 56 ms 8024 KB Output is correct
24 Correct 137 ms 10332 KB Output is correct
25 Correct 136 ms 10076 KB Output is correct
26 Correct 142 ms 10248 KB Output is correct
27 Correct 147 ms 10072 KB Output is correct
28 Correct 138 ms 10072 KB Output is correct
29 Correct 121 ms 10072 KB Output is correct
30 Correct 103 ms 10244 KB Output is correct
31 Correct 145 ms 10248 KB Output is correct
32 Correct 136 ms 10244 KB Output is correct
33 Correct 109 ms 10076 KB Output is correct
34 Correct 112 ms 10076 KB Output is correct
35 Correct 116 ms 10076 KB Output is correct
36 Correct 136 ms 10072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 5976 KB Output is correct
2 Correct 14 ms 5976 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 14 ms 5980 KB Output is correct
5 Correct 22 ms 8028 KB Output is correct
6 Correct 15 ms 5976 KB Output is correct
7 Correct 14 ms 6132 KB Output is correct
8 Correct 19 ms 8028 KB Output is correct
9 Correct 18 ms 8028 KB Output is correct
10 Correct 28 ms 8028 KB Output is correct
11 Correct 30 ms 8028 KB Output is correct
12 Correct 28 ms 8024 KB Output is correct
13 Correct 25 ms 8028 KB Output is correct
14 Correct 32 ms 8028 KB Output is correct
15 Correct 28 ms 8028 KB Output is correct
16 Correct 30 ms 8280 KB Output is correct
17 Correct 22 ms 8028 KB Output is correct
18 Correct 26 ms 8208 KB Output is correct
19 Correct 28 ms 8028 KB Output is correct
20 Correct 26 ms 8060 KB Output is correct
21 Correct 75 ms 8028 KB Output is correct
22 Correct 87 ms 8028 KB Output is correct
23 Correct 56 ms 8024 KB Output is correct
24 Correct 137 ms 10332 KB Output is correct
25 Correct 136 ms 10076 KB Output is correct
26 Correct 142 ms 10248 KB Output is correct
27 Correct 147 ms 10072 KB Output is correct
28 Correct 138 ms 10072 KB Output is correct
29 Correct 121 ms 10072 KB Output is correct
30 Correct 103 ms 10244 KB Output is correct
31 Correct 145 ms 10248 KB Output is correct
32 Correct 136 ms 10244 KB Output is correct
33 Correct 109 ms 10076 KB Output is correct
34 Correct 112 ms 10076 KB Output is correct
35 Correct 116 ms 10076 KB Output is correct
36 Correct 136 ms 10072 KB Output is correct
37 Correct 436 ms 14360 KB Output is correct
38 Correct 484 ms 14420 KB Output is correct
39 Correct 508 ms 16404 KB Output is correct
40 Correct 767 ms 16416 KB Output is correct
41 Correct 579 ms 16408 KB Output is correct
42 Correct 665 ms 16408 KB Output is correct
43 Correct 750 ms 16412 KB Output is correct
44 Correct 764 ms 16464 KB Output is correct
45 Correct 772 ms 16404 KB Output is correct
46 Correct 511 ms 16216 KB Output is correct
47 Correct 675 ms 16468 KB Output is correct
48 Correct 719 ms 16416 KB Output is correct
49 Correct 582 ms 16472 KB Output is correct
50 Correct 676 ms 16408 KB Output is correct
51 Correct 5 ms 12892 KB Output is correct
52 Correct 903 ms 16400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 5976 KB Output is correct
2 Correct 14 ms 5976 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 14 ms 5980 KB Output is correct
5 Correct 22 ms 8028 KB Output is correct
6 Correct 15 ms 5976 KB Output is correct
7 Correct 14 ms 6132 KB Output is correct
8 Correct 19 ms 8028 KB Output is correct
9 Correct 18 ms 8028 KB Output is correct
10 Correct 28 ms 8028 KB Output is correct
11 Correct 30 ms 8028 KB Output is correct
12 Correct 28 ms 8024 KB Output is correct
13 Correct 25 ms 8028 KB Output is correct
14 Correct 32 ms 8028 KB Output is correct
15 Correct 28 ms 8028 KB Output is correct
16 Correct 30 ms 8280 KB Output is correct
17 Correct 22 ms 8028 KB Output is correct
18 Correct 26 ms 8208 KB Output is correct
19 Correct 28 ms 8028 KB Output is correct
20 Correct 26 ms 8060 KB Output is correct
21 Correct 75 ms 8028 KB Output is correct
22 Correct 87 ms 8028 KB Output is correct
23 Correct 56 ms 8024 KB Output is correct
24 Correct 137 ms 10332 KB Output is correct
25 Correct 136 ms 10076 KB Output is correct
26 Correct 142 ms 10248 KB Output is correct
27 Correct 147 ms 10072 KB Output is correct
28 Correct 138 ms 10072 KB Output is correct
29 Correct 121 ms 10072 KB Output is correct
30 Correct 103 ms 10244 KB Output is correct
31 Correct 145 ms 10248 KB Output is correct
32 Correct 136 ms 10244 KB Output is correct
33 Correct 109 ms 10076 KB Output is correct
34 Correct 112 ms 10076 KB Output is correct
35 Correct 116 ms 10076 KB Output is correct
36 Correct 136 ms 10072 KB Output is correct
37 Correct 436 ms 14360 KB Output is correct
38 Correct 484 ms 14420 KB Output is correct
39 Correct 508 ms 16404 KB Output is correct
40 Correct 767 ms 16416 KB Output is correct
41 Correct 579 ms 16408 KB Output is correct
42 Correct 665 ms 16408 KB Output is correct
43 Correct 750 ms 16412 KB Output is correct
44 Correct 764 ms 16464 KB Output is correct
45 Correct 772 ms 16404 KB Output is correct
46 Correct 511 ms 16216 KB Output is correct
47 Correct 675 ms 16468 KB Output is correct
48 Correct 719 ms 16416 KB Output is correct
49 Correct 582 ms 16472 KB Output is correct
50 Correct 676 ms 16408 KB Output is correct
51 Correct 5 ms 12892 KB Output is correct
52 Correct 903 ms 16400 KB Output is correct
53 Correct 995 ms 16404 KB Output is correct
54 Execution timed out 1037 ms 18264 KB Time limit exceeded
55 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 5976 KB Output is correct
2 Correct 14 ms 5976 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 14 ms 5980 KB Output is correct
5 Correct 22 ms 8028 KB Output is correct
6 Correct 15 ms 5976 KB Output is correct
7 Correct 14 ms 6132 KB Output is correct
8 Correct 19 ms 8028 KB Output is correct
9 Correct 18 ms 8028 KB Output is correct
10 Correct 28 ms 8028 KB Output is correct
11 Correct 30 ms 8028 KB Output is correct
12 Correct 28 ms 8024 KB Output is correct
13 Correct 25 ms 8028 KB Output is correct
14 Correct 32 ms 8028 KB Output is correct
15 Correct 28 ms 8028 KB Output is correct
16 Correct 30 ms 8280 KB Output is correct
17 Correct 22 ms 8028 KB Output is correct
18 Correct 26 ms 8208 KB Output is correct
19 Correct 28 ms 8028 KB Output is correct
20 Correct 26 ms 8060 KB Output is correct
21 Correct 75 ms 8028 KB Output is correct
22 Correct 87 ms 8028 KB Output is correct
23 Correct 56 ms 8024 KB Output is correct
24 Correct 137 ms 10332 KB Output is correct
25 Correct 136 ms 10076 KB Output is correct
26 Correct 142 ms 10248 KB Output is correct
27 Correct 147 ms 10072 KB Output is correct
28 Correct 138 ms 10072 KB Output is correct
29 Correct 121 ms 10072 KB Output is correct
30 Correct 103 ms 10244 KB Output is correct
31 Correct 145 ms 10248 KB Output is correct
32 Correct 136 ms 10244 KB Output is correct
33 Correct 109 ms 10076 KB Output is correct
34 Correct 112 ms 10076 KB Output is correct
35 Correct 116 ms 10076 KB Output is correct
36 Correct 136 ms 10072 KB Output is correct
37 Correct 436 ms 14360 KB Output is correct
38 Correct 484 ms 14420 KB Output is correct
39 Correct 508 ms 16404 KB Output is correct
40 Correct 767 ms 16416 KB Output is correct
41 Correct 579 ms 16408 KB Output is correct
42 Correct 665 ms 16408 KB Output is correct
43 Correct 750 ms 16412 KB Output is correct
44 Correct 764 ms 16464 KB Output is correct
45 Correct 772 ms 16404 KB Output is correct
46 Correct 511 ms 16216 KB Output is correct
47 Correct 675 ms 16468 KB Output is correct
48 Correct 719 ms 16416 KB Output is correct
49 Correct 582 ms 16472 KB Output is correct
50 Correct 676 ms 16408 KB Output is correct
51 Correct 5 ms 12892 KB Output is correct
52 Correct 903 ms 16400 KB Output is correct
53 Correct 995 ms 16404 KB Output is correct
54 Execution timed out 1037 ms 18264 KB Time limit exceeded
55 Halted 0 ms 0 KB -