Submission #1129157

#TimeUsernameProblemLanguageResultExecution timeMemory
1129157alimkhanKpart (eJOI21_kpart)C++20
100 / 100
1182 ms888 KiB
//Bismillahir-Rahmanir-Rahim
#include <bits/stdc++.h>
 
using namespace std;

#define pb push_back
#define ll long long
#define ld long double
#define dbg(x) cerr << #x << " = " << x << "\n";
#define ff first
#define ss second

/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma comment (linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

const long long INF = 1e18 + 7;
const long long MOD = 1e9 + 7;
const int maxn = 2e5 + 20;
// const int lg = 20;

int n, dp[maxn], a[maxn];
bool ok[maxn];

void press_F_() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		ok[i] = 1;
	}
	for (int i = 1; i <= (int)1e5; i++) {
		dp[i] = 0;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = (int)1e5 - a[i]; j >= 1; j--) {
			dp[a[i] + j] = max(dp[a[i] + j], dp[j]);
		}
		dp[a[i]] = i;
		int sum = 0;
		for (int j = i; j >= 1; j--) {
			sum += a[j];
			if (sum % 2 != 0) {
				ok[i - j + 1] = 0;
			}
			if (ok[i - j + 1] == 1) {
				if (dp[sum / 2] < j) {
					ok[i - j + 1] = 0;
				}
			} 
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += ok[i];
	}
	cout << ans << " ";
	for (int i = 1; i <= n; i++) {
		if (ok[i] == 1) {
			cout << i << " ";
		}
	}
	cout << '\n';
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T = 1;
    cin >> T;
    for (int _ = 1; _ <= T; ++_) {
        // cout << "Case " << _ << ": ";
        press_F_();
    }
    //Respa gold 2025 InshAllah
    // return 0;
}
/*
Maybe not today and tomorrow, but InshAllah one day I will reach cm
*/
// g++ -std=c++17 main.cpp
// ./a.out
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...