Submission #501606

# Submission time Handle Problem Language Result Execution time Memory
501606 2022-01-04T07:11:36 Z shmad Bootfall (IZhO17_bootfall) C++17
13 / 100
1000 ms 8168 KB
#include <bits/stdc++.h>

#define int long long
#define vt vector
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define ff first
#define ss second
#define dbg(x) cerr << #x << " = " << x << '\n'

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vvi = vt< vt<int> >;

const int N = 1e6 + 5, mod = 1e9 + 7, inf = 1e18 + 7, B = 500, LIM = (1ll << 60);
const double eps = 1e-6;

template<class Iterator> std::ostream& print_range(std::ostream& os, Iterator begin, Iterator end) {
    os << "{";
    for (auto it = begin; it != end; os << *it++) if (it != begin) os << ", ";
    return os << "}";
}
 
template<class X> std::ostream& operator<<(std::ostream& os, const std::vector<X>& vec) {
    return print_range(os, all(vec));
}

int dp[N];

void solve () {
	int n;
	cin >> n;
	vt<int> a(n + 1);
	int sum = 0;
	for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i];
	if (n & 1) cout << "0\n", exit(0);
	set<int> ans;
	vt<int> used(N, 0);
	dp[0] = 1;
	for (int val = 1; val <= sum; val++) {
		for (int i = 1; i <= n; i++) {
			int x = a[i], s = sum - a[i];
			a[i] = val;
			s += a[i];
			if (s & 1) {
				a[i] = x;
				continue;
			}
			for (int j = 1; j <= n; j++) {
				for (int w = s - a[j]; w >= 0; w--) {
					if (dp[w] == 1) dp[w + a[j]] = 1;
				}
			}
			if (dp[s / 2] == 1) {
            	used[val]++;
            	if (used[val] >= n) ans.insert(val);
            }
			a[i] = x;
			for (int j = 1; j <= s; j++) dp[j] = 0;
		}
	}
	cout << sz(ans) << '\n';
	for (auto x: ans) cout << x << ' ';
	cout << '\n';
}

bool testcases = 0;
                  
signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    int test = 1;
    if (testcases) cin >> test;
    for (int cs = 1; cs <= test; cs++) {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8140 KB Output is correct
2 Correct 3 ms 8140 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 7 ms 8080 KB Output is correct
5 Correct 121 ms 8168 KB Output is correct
6 Correct 5 ms 8140 KB Output is correct
7 Correct 5 ms 8140 KB Output is correct
8 Correct 269 ms 8156 KB Output is correct
9 Correct 30 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8140 KB Output is correct
2 Correct 3 ms 8140 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 7 ms 8080 KB Output is correct
5 Correct 121 ms 8168 KB Output is correct
6 Correct 5 ms 8140 KB Output is correct
7 Correct 5 ms 8140 KB Output is correct
8 Correct 269 ms 8156 KB Output is correct
9 Correct 30 ms 8140 KB Output is correct
10 Correct 195 ms 8148 KB Output is correct
11 Correct 80 ms 8140 KB Output is correct
12 Correct 116 ms 8140 KB Output is correct
13 Correct 59 ms 8156 KB Output is correct
14 Correct 90 ms 8148 KB Output is correct
15 Correct 48 ms 8140 KB Output is correct
16 Correct 68 ms 8140 KB Output is correct
17 Correct 17 ms 8140 KB Output is correct
18 Correct 44 ms 8156 KB Output is correct
19 Correct 37 ms 8168 KB Output is correct
20 Correct 210 ms 8156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8140 KB Output is correct
2 Correct 3 ms 8140 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 7 ms 8080 KB Output is correct
5 Correct 121 ms 8168 KB Output is correct
6 Correct 5 ms 8140 KB Output is correct
7 Correct 5 ms 8140 KB Output is correct
8 Correct 269 ms 8156 KB Output is correct
9 Correct 30 ms 8140 KB Output is correct
10 Correct 195 ms 8148 KB Output is correct
11 Correct 80 ms 8140 KB Output is correct
12 Correct 116 ms 8140 KB Output is correct
13 Correct 59 ms 8156 KB Output is correct
14 Correct 90 ms 8148 KB Output is correct
15 Correct 48 ms 8140 KB Output is correct
16 Correct 68 ms 8140 KB Output is correct
17 Correct 17 ms 8140 KB Output is correct
18 Correct 44 ms 8156 KB Output is correct
19 Correct 37 ms 8168 KB Output is correct
20 Correct 210 ms 8156 KB Output is correct
21 Execution timed out 1090 ms 8164 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8140 KB Output is correct
2 Correct 3 ms 8140 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 7 ms 8080 KB Output is correct
5 Correct 121 ms 8168 KB Output is correct
6 Correct 5 ms 8140 KB Output is correct
7 Correct 5 ms 8140 KB Output is correct
8 Correct 269 ms 8156 KB Output is correct
9 Correct 30 ms 8140 KB Output is correct
10 Correct 195 ms 8148 KB Output is correct
11 Correct 80 ms 8140 KB Output is correct
12 Correct 116 ms 8140 KB Output is correct
13 Correct 59 ms 8156 KB Output is correct
14 Correct 90 ms 8148 KB Output is correct
15 Correct 48 ms 8140 KB Output is correct
16 Correct 68 ms 8140 KB Output is correct
17 Correct 17 ms 8140 KB Output is correct
18 Correct 44 ms 8156 KB Output is correct
19 Correct 37 ms 8168 KB Output is correct
20 Correct 210 ms 8156 KB Output is correct
21 Execution timed out 1090 ms 8164 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8140 KB Output is correct
2 Correct 3 ms 8140 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 7 ms 8080 KB Output is correct
5 Correct 121 ms 8168 KB Output is correct
6 Correct 5 ms 8140 KB Output is correct
7 Correct 5 ms 8140 KB Output is correct
8 Correct 269 ms 8156 KB Output is correct
9 Correct 30 ms 8140 KB Output is correct
10 Correct 195 ms 8148 KB Output is correct
11 Correct 80 ms 8140 KB Output is correct
12 Correct 116 ms 8140 KB Output is correct
13 Correct 59 ms 8156 KB Output is correct
14 Correct 90 ms 8148 KB Output is correct
15 Correct 48 ms 8140 KB Output is correct
16 Correct 68 ms 8140 KB Output is correct
17 Correct 17 ms 8140 KB Output is correct
18 Correct 44 ms 8156 KB Output is correct
19 Correct 37 ms 8168 KB Output is correct
20 Correct 210 ms 8156 KB Output is correct
21 Execution timed out 1090 ms 8164 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8140 KB Output is correct
2 Correct 3 ms 8140 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 7 ms 8080 KB Output is correct
5 Correct 121 ms 8168 KB Output is correct
6 Correct 5 ms 8140 KB Output is correct
7 Correct 5 ms 8140 KB Output is correct
8 Correct 269 ms 8156 KB Output is correct
9 Correct 30 ms 8140 KB Output is correct
10 Correct 195 ms 8148 KB Output is correct
11 Correct 80 ms 8140 KB Output is correct
12 Correct 116 ms 8140 KB Output is correct
13 Correct 59 ms 8156 KB Output is correct
14 Correct 90 ms 8148 KB Output is correct
15 Correct 48 ms 8140 KB Output is correct
16 Correct 68 ms 8140 KB Output is correct
17 Correct 17 ms 8140 KB Output is correct
18 Correct 44 ms 8156 KB Output is correct
19 Correct 37 ms 8168 KB Output is correct
20 Correct 210 ms 8156 KB Output is correct
21 Execution timed out 1090 ms 8164 KB Time limit exceeded
22 Halted 0 ms 0 KB -