Submission #1037225

# Submission time Handle Problem Language Result Execution time Memory
1037225 2024-07-28T11:05:20 Z ByeWorld Bootfall (IZhO17_bootfall) C++14
13 / 100
1000 ms 16844 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define int long long
#define ll long long
#define pb push_back
#define fi first
#define se second
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> ipii;
const int MAXN = 505;
const int MAXA = 250100;
const int MAXK = 1e5+10;
const int INF = 1e18+10;
void chmn(int &a, int b){ a = min(a, b); }

int n;
int a[MAXN], mx;
vector <int> ans;
bool dp[MAXN][MAXA];

void cek(int x){
	bool can = 1;
	for(int i=1; i<=n; i++){ 
		int sum = x;
		vector <int> vec; vec.pb(-1);
		for(int j=1; j<=n; j++)
			if(i!=j) vec.pb(a[j]), sum += a[j];
		vec.pb(x);
		if(sum%2 == 1){
			can = 0; break;
		}

		for(int j=0; j<=n; j++)
			for(int k=0; k<=sum/2; k++) dp[j][k] = 0;
		dp[0][0] = 1;
		
		// for(auto in : vec) cout << in << ' ';
		// 	cout << "xx\n";
		for(int j=1; j<=n; j++){
			for(int k=0; k<=sum/2; k++){
				dp[j][k] = dp[j-1][k];
				if(k>=vec[j]) dp[j][k] |= dp[j-1][k-vec[j]];
			}
		}
		// cout << x << ' ' << dp[n][sum/2] << ' '<< sum<< " pp\n";
		can &= dp[n][sum/2];
	}
	if(can) ans.pb(x);
}
signed main(){
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i=1; i<=n; i++){ cin >> a[i]; mx += a[i]; }

    dp[0][0] = 1;
	for(int j=1; j<=n; j++){
		for(int k=0; k<=mx/2; k++){
			dp[j][k] = dp[j-1][k];
			if(k>=a[j]) dp[j][k] |= dp[j-1][k-a[j]];
		}
	}
	if(mx%2==1 || !dp[n][mx/2]){
		cout << "0\n"; exit(0);
	}

    for(int i=1; i<=mx; i++) cek(i);
    cout << ans.size() << '\n';
    for(auto in : ans) cout << in << ' ';
    cout << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 6 ms 4444 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 15 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 6 ms 4444 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 15 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 14 ms 8536 KB Output is correct
11 Correct 5 ms 8540 KB Output is correct
12 Correct 9 ms 8540 KB Output is correct
13 Correct 1 ms 8536 KB Output is correct
14 Correct 5 ms 8540 KB Output is correct
15 Correct 4 ms 8540 KB Output is correct
16 Correct 5 ms 8664 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 4 ms 6492 KB Output is correct
19 Correct 3 ms 8540 KB Output is correct
20 Correct 16 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 6 ms 4444 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 15 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 14 ms 8536 KB Output is correct
11 Correct 5 ms 8540 KB Output is correct
12 Correct 9 ms 8540 KB Output is correct
13 Correct 1 ms 8536 KB Output is correct
14 Correct 5 ms 8540 KB Output is correct
15 Correct 4 ms 8540 KB Output is correct
16 Correct 5 ms 8664 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 4 ms 6492 KB Output is correct
19 Correct 3 ms 8540 KB Output is correct
20 Correct 16 ms 8540 KB Output is correct
21 Execution timed out 1055 ms 16844 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 6 ms 4444 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 15 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 14 ms 8536 KB Output is correct
11 Correct 5 ms 8540 KB Output is correct
12 Correct 9 ms 8540 KB Output is correct
13 Correct 1 ms 8536 KB Output is correct
14 Correct 5 ms 8540 KB Output is correct
15 Correct 4 ms 8540 KB Output is correct
16 Correct 5 ms 8664 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 4 ms 6492 KB Output is correct
19 Correct 3 ms 8540 KB Output is correct
20 Correct 16 ms 8540 KB Output is correct
21 Execution timed out 1055 ms 16844 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 6 ms 4444 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 15 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 14 ms 8536 KB Output is correct
11 Correct 5 ms 8540 KB Output is correct
12 Correct 9 ms 8540 KB Output is correct
13 Correct 1 ms 8536 KB Output is correct
14 Correct 5 ms 8540 KB Output is correct
15 Correct 4 ms 8540 KB Output is correct
16 Correct 5 ms 8664 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 4 ms 6492 KB Output is correct
19 Correct 3 ms 8540 KB Output is correct
20 Correct 16 ms 8540 KB Output is correct
21 Execution timed out 1055 ms 16844 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 6 ms 4444 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 15 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 14 ms 8536 KB Output is correct
11 Correct 5 ms 8540 KB Output is correct
12 Correct 9 ms 8540 KB Output is correct
13 Correct 1 ms 8536 KB Output is correct
14 Correct 5 ms 8540 KB Output is correct
15 Correct 4 ms 8540 KB Output is correct
16 Correct 5 ms 8664 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 4 ms 6492 KB Output is correct
19 Correct 3 ms 8540 KB Output is correct
20 Correct 16 ms 8540 KB Output is correct
21 Execution timed out 1055 ms 16844 KB Time limit exceeded
22 Halted 0 ms 0 KB -