Submission #645717

# Submission time Handle Problem Language Result Execution time Memory
645717 2022-09-27T17:41:37 Z Koful123 Kpart (eJOI21_kpart) C++17
30 / 100
2000 ms 383496 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};
	for(int i=1;i<=n;i++){
		cin >> v[i]; sum += v[i];
	}

	int dp[n+1][sum + 1];
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++){
		for(int j=sum;j>=1;j--){
			dp[i][j] = dp[i-1][j];
			if(j + v[i] <= sum){
				dp[i][j+v[i]] = max(dp[i][j+v[i]],dp[i][j]);
			}
		}
		dp[i][v[i]] = max(dp[i-1][v[i]],i);
	}

	vector<int> ans;
	for(int i=1,tot=0;i<=n;tot += v[i],i++){
		int ok = 1,sum = tot;
		for(int j=i;j<=n;j++){
			sum -= v[j-i],sum += v[j];
			if(sum % 2 || dp[j][sum / 2] <= j-i){
				ok = 0;break;
			}
		}
		if(ok) 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 2 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 2180 KB Output is correct
2 Correct 35 ms 6536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 164 ms 26100 KB Output is correct
2 Correct 405 ms 59112 KB Output is correct
3 Correct 483 ms 75332 KB Output is correct
4 Correct 838 ms 128600 KB Output is correct
5 Correct 1980 ms 317676 KB Output is correct
6 Execution timed out 2091 ms 383496 KB Time limit exceeded
7 Halted 0 ms 0 KB -