답안 #514491

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
514491 2022-01-18T08:16:29 Z Mazaalai Bootfall (IZhO17_bootfall) C++17
28 / 100
1000 ms 1640 KB
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int n, m;
const int N = 270+5;
const int M = 270*270 + 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';
      |                                               ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 588 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 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 0 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 588 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 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 0 ms 588 KB Output is correct
21 Correct 59 ms 740 KB Output is correct
22 Correct 82 ms 764 KB Output is correct
23 Correct 25 ms 712 KB Output is correct
24 Correct 202 ms 816 KB Output is correct
25 Correct 279 ms 956 KB Output is correct
26 Correct 330 ms 976 KB Output is correct
27 Correct 126 ms 796 KB Output is correct
28 Correct 79 ms 764 KB Output is correct
29 Correct 108 ms 812 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 481 ms 956 KB Output is correct
32 Correct 218 ms 836 KB Output is correct
33 Correct 1 ms 588 KB Output is correct
34 Correct 1 ms 588 KB Output is correct
35 Correct 56 ms 764 KB Output is correct
36 Correct 200 ms 836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 588 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 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 0 ms 588 KB Output is correct
21 Correct 59 ms 740 KB Output is correct
22 Correct 82 ms 764 KB Output is correct
23 Correct 25 ms 712 KB Output is correct
24 Correct 202 ms 816 KB Output is correct
25 Correct 279 ms 956 KB Output is correct
26 Correct 330 ms 976 KB Output is correct
27 Correct 126 ms 796 KB Output is correct
28 Correct 79 ms 764 KB Output is correct
29 Correct 108 ms 812 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 481 ms 956 KB Output is correct
32 Correct 218 ms 836 KB Output is correct
33 Correct 1 ms 588 KB Output is correct
34 Correct 1 ms 588 KB Output is correct
35 Correct 56 ms 764 KB Output is correct
36 Correct 200 ms 836 KB Output is correct
37 Execution timed out 1076 ms 1640 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 588 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 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 0 ms 588 KB Output is correct
21 Correct 59 ms 740 KB Output is correct
22 Correct 82 ms 764 KB Output is correct
23 Correct 25 ms 712 KB Output is correct
24 Correct 202 ms 816 KB Output is correct
25 Correct 279 ms 956 KB Output is correct
26 Correct 330 ms 976 KB Output is correct
27 Correct 126 ms 796 KB Output is correct
28 Correct 79 ms 764 KB Output is correct
29 Correct 108 ms 812 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 481 ms 956 KB Output is correct
32 Correct 218 ms 836 KB Output is correct
33 Correct 1 ms 588 KB Output is correct
34 Correct 1 ms 588 KB Output is correct
35 Correct 56 ms 764 KB Output is correct
36 Correct 200 ms 836 KB Output is correct
37 Execution timed out 1076 ms 1640 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 588 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 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 0 ms 588 KB Output is correct
21 Correct 59 ms 740 KB Output is correct
22 Correct 82 ms 764 KB Output is correct
23 Correct 25 ms 712 KB Output is correct
24 Correct 202 ms 816 KB Output is correct
25 Correct 279 ms 956 KB Output is correct
26 Correct 330 ms 976 KB Output is correct
27 Correct 126 ms 796 KB Output is correct
28 Correct 79 ms 764 KB Output is correct
29 Correct 108 ms 812 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 481 ms 956 KB Output is correct
32 Correct 218 ms 836 KB Output is correct
33 Correct 1 ms 588 KB Output is correct
34 Correct 1 ms 588 KB Output is correct
35 Correct 56 ms 764 KB Output is correct
36 Correct 200 ms 836 KB Output is correct
37 Execution timed out 1076 ms 1640 KB Time limit exceeded
38 Halted 0 ms 0 KB -