Submission #514486

# Submission time Handle Problem Language Result Execution time Memory
514486 2022-01-18T08:13:24 Z Mazaalai Bootfall (IZhO17_bootfall) C++17
28 / 100
1000 ms 2324 KB
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int n, m;
const int N = 505;
const int M = 500*500 + 5;
const int K = M / 2;
vector <int> ans;
int nums[N], pre[K], suf[K], sum;
int gcd(int a, int b) {
	if (a == 0) return b;
	return gcd(b%a, a);
}
signed main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> nums[i];
	}
	int ggcd = nums[1];
	for (int i = 2; i <= n; i++) 
		ggcd = gcd(ggcd, nums[i]);
	for (int i = 1; i <= n; i++) {
		nums[i] /= ggcd;
		if (nums[i] % 2 == 0) {
			sum = 1;
			break;
		}
		sum += nums[i];
	}
	if (sum & 1 || n & 1) {
		cout << "0\n";
		return 0;
	}
	memset(pre, -1, sizeof(pre));
	memset(suf, -1, sizeof(suf));
	set <int> vals;

	pre[0] = 0;
	vals.insert(0);
	for (int i = 1; i <= n; i++) {
		vector <int> add;
		for (auto& el : vals) {
			int sum = el + nums[i];
			if (sum >= K || pre[sum] != -1) continue;
			pre[sum] = i;
			add.pb(sum);
		}
		for (auto& el : add) vals.insert(el);
	}
	vals.clear();
	suf[0] = n+1;
	vals.insert(0);
	for (int i = n; i > 0; i--) {
		vector <int> add;
		for (auto& el : vals) {
			int sum = el + nums[i];
			if (sum >= K || suf[sum] != -1) continue;
			suf[sum] = i;
			add.pb(sum);
		}
		for (auto& el : add) vals.insert(el);
	}
// for (int i = 1; i <= 50; i++) cout << pre[i] << " \n"[i==50];
// for (int i = 1; i <= 50; i++) cout << suf[i] << " \n"[i==50];
	for (int i = 1; i <= sum; i++) {
		bool possible = 1;
		int totalSum = sum + i, target;
		if (totalSum % 2 == 0) continue;
		for (int j = 1; j <= n && possible; j++) {
			target = (totalSum - nums[j]) / 2;
			bool cur = 0;
			for (int k = 0; k * 2 <= target && !cur; k++) {
				if (pre[k] != -1 && suf[target-k] != -1)
					cur |= (pre[k] < j && j < suf[target-k]);
				if (suf[k] != -1 && pre[target-k] != -1)
					cur |= (pre[target-k] < j && j < suf[k]);
			}
			possible &= cur;
		}
		if (possible) ans.pb(i);
	}



	cout << ans.size() << '\n';
	for (auto& el : ans) cout << el*ggcd << ' '; cout << '\n';
}


















Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:91:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   91 |  for (auto& el : ans) cout << el*ggcd << ' '; cout << '\n';
      |  ^~~
bootfall.cpp:91:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   91 |  for (auto& el : ans) cout << el*ggcd << ' '; cout << '\n';
      |                                               ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1200 KB Output is correct
2 Correct 1 ms 1200 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Correct 1 ms 1224 KB Output is correct
5 Correct 2 ms 1208 KB Output is correct
6 Correct 1 ms 1192 KB Output is correct
7 Correct 1 ms 1208 KB Output is correct
8 Correct 1 ms 1212 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1200 KB Output is correct
2 Correct 1 ms 1200 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Correct 1 ms 1224 KB Output is correct
5 Correct 2 ms 1208 KB Output is correct
6 Correct 1 ms 1192 KB Output is correct
7 Correct 1 ms 1208 KB Output is correct
8 Correct 1 ms 1212 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 1216 KB Output is correct
11 Correct 1 ms 1208 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 2 ms 1212 KB Output is correct
15 Correct 1 ms 1212 KB Output is correct
16 Correct 1 ms 1228 KB Output is correct
17 Correct 1 ms 1228 KB Output is correct
18 Correct 1 ms 1228 KB Output is correct
19 Correct 1 ms 1212 KB Output is correct
20 Correct 1 ms 1216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1200 KB Output is correct
2 Correct 1 ms 1200 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Correct 1 ms 1224 KB Output is correct
5 Correct 2 ms 1208 KB Output is correct
6 Correct 1 ms 1192 KB Output is correct
7 Correct 1 ms 1208 KB Output is correct
8 Correct 1 ms 1212 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 1216 KB Output is correct
11 Correct 1 ms 1208 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 2 ms 1212 KB Output is correct
15 Correct 1 ms 1212 KB Output is correct
16 Correct 1 ms 1228 KB Output is correct
17 Correct 1 ms 1228 KB Output is correct
18 Correct 1 ms 1228 KB Output is correct
19 Correct 1 ms 1212 KB Output is correct
20 Correct 1 ms 1216 KB Output is correct
21 Correct 59 ms 1456 KB Output is correct
22 Correct 87 ms 1456 KB Output is correct
23 Correct 25 ms 1416 KB Output is correct
24 Correct 204 ms 1508 KB Output is correct
25 Correct 260 ms 1640 KB Output is correct
26 Correct 323 ms 1780 KB Output is correct
27 Correct 122 ms 1484 KB Output is correct
28 Correct 78 ms 1472 KB Output is correct
29 Correct 108 ms 1500 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 491 ms 1776 KB Output is correct
32 Correct 248 ms 1524 KB Output is correct
33 Correct 1 ms 1228 KB Output is correct
34 Correct 1 ms 1228 KB Output is correct
35 Correct 54 ms 1464 KB Output is correct
36 Correct 213 ms 1516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1200 KB Output is correct
2 Correct 1 ms 1200 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Correct 1 ms 1224 KB Output is correct
5 Correct 2 ms 1208 KB Output is correct
6 Correct 1 ms 1192 KB Output is correct
7 Correct 1 ms 1208 KB Output is correct
8 Correct 1 ms 1212 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 1216 KB Output is correct
11 Correct 1 ms 1208 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 2 ms 1212 KB Output is correct
15 Correct 1 ms 1212 KB Output is correct
16 Correct 1 ms 1228 KB Output is correct
17 Correct 1 ms 1228 KB Output is correct
18 Correct 1 ms 1228 KB Output is correct
19 Correct 1 ms 1212 KB Output is correct
20 Correct 1 ms 1216 KB Output is correct
21 Correct 59 ms 1456 KB Output is correct
22 Correct 87 ms 1456 KB Output is correct
23 Correct 25 ms 1416 KB Output is correct
24 Correct 204 ms 1508 KB Output is correct
25 Correct 260 ms 1640 KB Output is correct
26 Correct 323 ms 1780 KB Output is correct
27 Correct 122 ms 1484 KB Output is correct
28 Correct 78 ms 1472 KB Output is correct
29 Correct 108 ms 1500 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 491 ms 1776 KB Output is correct
32 Correct 248 ms 1524 KB Output is correct
33 Correct 1 ms 1228 KB Output is correct
34 Correct 1 ms 1228 KB Output is correct
35 Correct 54 ms 1464 KB Output is correct
36 Correct 213 ms 1516 KB Output is correct
37 Execution timed out 1053 ms 2324 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1200 KB Output is correct
2 Correct 1 ms 1200 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Correct 1 ms 1224 KB Output is correct
5 Correct 2 ms 1208 KB Output is correct
6 Correct 1 ms 1192 KB Output is correct
7 Correct 1 ms 1208 KB Output is correct
8 Correct 1 ms 1212 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 1216 KB Output is correct
11 Correct 1 ms 1208 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 2 ms 1212 KB Output is correct
15 Correct 1 ms 1212 KB Output is correct
16 Correct 1 ms 1228 KB Output is correct
17 Correct 1 ms 1228 KB Output is correct
18 Correct 1 ms 1228 KB Output is correct
19 Correct 1 ms 1212 KB Output is correct
20 Correct 1 ms 1216 KB Output is correct
21 Correct 59 ms 1456 KB Output is correct
22 Correct 87 ms 1456 KB Output is correct
23 Correct 25 ms 1416 KB Output is correct
24 Correct 204 ms 1508 KB Output is correct
25 Correct 260 ms 1640 KB Output is correct
26 Correct 323 ms 1780 KB Output is correct
27 Correct 122 ms 1484 KB Output is correct
28 Correct 78 ms 1472 KB Output is correct
29 Correct 108 ms 1500 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 491 ms 1776 KB Output is correct
32 Correct 248 ms 1524 KB Output is correct
33 Correct 1 ms 1228 KB Output is correct
34 Correct 1 ms 1228 KB Output is correct
35 Correct 54 ms 1464 KB Output is correct
36 Correct 213 ms 1516 KB Output is correct
37 Execution timed out 1053 ms 2324 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1200 KB Output is correct
2 Correct 1 ms 1200 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Correct 1 ms 1224 KB Output is correct
5 Correct 2 ms 1208 KB Output is correct
6 Correct 1 ms 1192 KB Output is correct
7 Correct 1 ms 1208 KB Output is correct
8 Correct 1 ms 1212 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 1216 KB Output is correct
11 Correct 1 ms 1208 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 2 ms 1212 KB Output is correct
15 Correct 1 ms 1212 KB Output is correct
16 Correct 1 ms 1228 KB Output is correct
17 Correct 1 ms 1228 KB Output is correct
18 Correct 1 ms 1228 KB Output is correct
19 Correct 1 ms 1212 KB Output is correct
20 Correct 1 ms 1216 KB Output is correct
21 Correct 59 ms 1456 KB Output is correct
22 Correct 87 ms 1456 KB Output is correct
23 Correct 25 ms 1416 KB Output is correct
24 Correct 204 ms 1508 KB Output is correct
25 Correct 260 ms 1640 KB Output is correct
26 Correct 323 ms 1780 KB Output is correct
27 Correct 122 ms 1484 KB Output is correct
28 Correct 78 ms 1472 KB Output is correct
29 Correct 108 ms 1500 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 491 ms 1776 KB Output is correct
32 Correct 248 ms 1524 KB Output is correct
33 Correct 1 ms 1228 KB Output is correct
34 Correct 1 ms 1228 KB Output is correct
35 Correct 54 ms 1464 KB Output is correct
36 Correct 213 ms 1516 KB Output is correct
37 Execution timed out 1053 ms 2324 KB Time limit exceeded
38 Halted 0 ms 0 KB -