Submission #645721

# Submission time Handle Problem Language Result Execution time Memory
645721 2022-09-27T17:54:40 Z Koful123 Kpart (eJOI21_kpart) C++17
100 / 100
1358 ms 828 KB
#include <bits/stdc++.h>
using namespace std;
#define double long double
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define mod 998244353
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

void solve(){

	int n,sum = 0;
	cin >> n;

	int v[n+1] = {0},ok[n+1];
	for(int i=1;i<=n;i++){
		cin >> v[i]; sum += v[i];
		ok[i] = 1;
	}

	int dp[sum + 1] = {0};
	for(int i=1,tot = v[1];i<=n;i++,tot += v[i]){
		for(int j=sum-v[i];j>=1;j--){
			dp[j+v[i]] = max(dp[j+v[i]],dp[j]);
		}
		dp[v[i]] = max(dp[v[i]],i);
		int sum = tot;
		for(int j=0;j<i;j++){
			sum -= v[j];
			if(sum % 2 || dp[sum / 2] <= j){
				ok[i-j] = 0;
			}
		}
	}

	vector<int> ans;
	for(int i=1;i<=n;i++){
		if(ok[i]) ans.pb(i);
	}

	cout << ans.size() << ' ';
	for(int x : ans){
		cout << x << ' ';
	}
	cout << endl;
}

signed main(){

	ios::sync_with_stdio(0);
	cin.tie(0);

	int t = 1;
	cin >> t;

	while(t--)
		solve();

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 19 ms 368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 340 KB Output is correct
2 Correct 215 ms 480 KB Output is correct
3 Correct 234 ms 492 KB Output is correct
4 Correct 433 ms 596 KB Output is correct
5 Correct 977 ms 716 KB Output is correct
6 Correct 1358 ms 828 KB Output is correct
7 Correct 1249 ms 776 KB Output is correct