Submission #514490

# Submission time Handle Problem Language Result Execution time Memory
514490 2022-01-18T08:15:53 Z Mazaalai Bootfall (IZhO17_bootfall) C++17
28 / 100
1000 ms 2264 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++) {
			if (i > totalSum - nums[j]) {
				possible = 0;
				break;
			}
			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 1228 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 1228 KB Output is correct
5 Correct 2 ms 1228 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 1 ms 1228 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 1228 KB Output is correct
5 Correct 2 ms 1228 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 1 ms 1228 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 1 ms 1228 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 1228 KB Output is correct
15 Correct 1 ms 1228 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 1228 KB Output is correct
20 Correct 1 ms 1228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 1228 KB Output is correct
5 Correct 2 ms 1228 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 1 ms 1228 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 1 ms 1228 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 1228 KB Output is correct
15 Correct 1 ms 1228 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 1228 KB Output is correct
20 Correct 1 ms 1228 KB Output is correct
21 Correct 57 ms 1356 KB Output is correct
22 Correct 94 ms 1484 KB Output is correct
23 Correct 24 ms 1400 KB Output is correct
24 Correct 215 ms 1512 KB Output is correct
25 Correct 280 ms 1744 KB Output is correct
26 Correct 356 ms 1764 KB Output is correct
27 Correct 128 ms 1484 KB Output is correct
28 Correct 81 ms 1464 KB Output is correct
29 Correct 110 ms 1508 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 457 ms 1648 KB Output is correct
32 Correct 262 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 64 ms 1460 KB Output is correct
36 Correct 211 ms 1484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 1228 KB Output is correct
5 Correct 2 ms 1228 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 1 ms 1228 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 1 ms 1228 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 1228 KB Output is correct
15 Correct 1 ms 1228 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 1228 KB Output is correct
20 Correct 1 ms 1228 KB Output is correct
21 Correct 57 ms 1356 KB Output is correct
22 Correct 94 ms 1484 KB Output is correct
23 Correct 24 ms 1400 KB Output is correct
24 Correct 215 ms 1512 KB Output is correct
25 Correct 280 ms 1744 KB Output is correct
26 Correct 356 ms 1764 KB Output is correct
27 Correct 128 ms 1484 KB Output is correct
28 Correct 81 ms 1464 KB Output is correct
29 Correct 110 ms 1508 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 457 ms 1648 KB Output is correct
32 Correct 262 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 64 ms 1460 KB Output is correct
36 Correct 211 ms 1484 KB Output is correct
37 Execution timed out 1086 ms 2264 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 1228 KB Output is correct
5 Correct 2 ms 1228 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 1 ms 1228 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 1 ms 1228 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 1228 KB Output is correct
15 Correct 1 ms 1228 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 1228 KB Output is correct
20 Correct 1 ms 1228 KB Output is correct
21 Correct 57 ms 1356 KB Output is correct
22 Correct 94 ms 1484 KB Output is correct
23 Correct 24 ms 1400 KB Output is correct
24 Correct 215 ms 1512 KB Output is correct
25 Correct 280 ms 1744 KB Output is correct
26 Correct 356 ms 1764 KB Output is correct
27 Correct 128 ms 1484 KB Output is correct
28 Correct 81 ms 1464 KB Output is correct
29 Correct 110 ms 1508 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 457 ms 1648 KB Output is correct
32 Correct 262 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 64 ms 1460 KB Output is correct
36 Correct 211 ms 1484 KB Output is correct
37 Execution timed out 1086 ms 2264 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1228 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 1228 KB Output is correct
5 Correct 2 ms 1228 KB Output is correct
6 Correct 1 ms 1228 KB Output is correct
7 Correct 1 ms 1228 KB Output is correct
8 Correct 1 ms 1228 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 1 ms 1228 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 1228 KB Output is correct
15 Correct 1 ms 1228 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 1228 KB Output is correct
20 Correct 1 ms 1228 KB Output is correct
21 Correct 57 ms 1356 KB Output is correct
22 Correct 94 ms 1484 KB Output is correct
23 Correct 24 ms 1400 KB Output is correct
24 Correct 215 ms 1512 KB Output is correct
25 Correct 280 ms 1744 KB Output is correct
26 Correct 356 ms 1764 KB Output is correct
27 Correct 128 ms 1484 KB Output is correct
28 Correct 81 ms 1464 KB Output is correct
29 Correct 110 ms 1508 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 457 ms 1648 KB Output is correct
32 Correct 262 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 64 ms 1460 KB Output is correct
36 Correct 211 ms 1484 KB Output is correct
37 Execution timed out 1086 ms 2264 KB Time limit exceeded
38 Halted 0 ms 0 KB -