Submission #828522

# Submission time Handle Problem Language Result Execution time Memory
828522 2023-08-17T10:44:13 Z ZeroCool Kpart (eJOI21_kpart) C++14
100 / 100
1516 ms 1176 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define mp make_pair
#define pb push_back

using ll = long long;
using ld = long double;


void solve(int T);
void pre();

const int mxn = 1e5 + 5;
const int SQRT = 500;
const int LOG = 20;
const int inf = 1e18;
const int mod = 1e9 + 7;
const ld eps = 1e-9;

int32_t main(){
	pre();
	int tt = 1;
	cin>>tt;
	for(int i = 1;i<=tt;i++)solve(i);
    return 0;
}



void pre(){
	#ifdef ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);
	#endif
	
}

int dp[mxn];

void solve(int T){
	int n;
	cin>>n;

	int A[n];
	for(int i = 0;i<n;i++)cin>>A[i];

	memset(dp, -1, sizeof dp);
	bool good[n+1];
	for(int i = 0;i<=n;i++)good[i] = true;
	for(int i = 0;i<n;i++){
		for(int j = mxn;j >= A[i];j--){
			dp[j] = max(dp[j], dp[j - A[i]]);
		}

		dp[A[i]] = i;

		int sum = 0;
		for(int j = i;j>=0;j--){
			sum += A[j];

			if(sum % 2 != 0 || dp[sum/2] < j)good[i - j + 1] = false;
		}
	}

	int cnt = 0;
	for(int i = 1;i<=n;i++){
		if(good[i])cnt++;
	}
	cout<<cnt<<" ";
	for(int i = 1;i<=n;i++){
		if(good[i])cout<<i<<" ";
	}
	cout<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 980 KB Output is correct
2 Correct 167 ms 1092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 312 ms 1092 KB Output is correct
2 Correct 604 ms 1100 KB Output is correct
3 Correct 569 ms 1112 KB Output is correct
4 Correct 799 ms 1116 KB Output is correct
5 Correct 1181 ms 1148 KB Output is correct
6 Correct 1516 ms 1176 KB Output is correct
7 Correct 1390 ms 1164 KB Output is correct