제출 #1161743

#제출 시각아이디문제언어결과실행 시간메모리
1161743strelok1337Kpart (eJOI21_kpart)C++20
100 / 100
922 ms888 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
#define F first
#define S second
#define IShowSpeed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(a) a.begin(),a.end()
const int N=1e3+10;
const ll inf = 1e18 + 1337;
const int mod=1e9+7;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
int a[N],sum[N],ans[N],dp[(int)5e4+2][2];

int main()
{
	//freopen("bank.in","r",stdin);
	//freopen("bank.out","w",stdout);
	IShowSpeed
	ll tt=1;
	cin>>tt;
	while(tt--)
	{
		ll n;
		cin>>n;
		for(int i=1;i<=n;i++) {
			cin>>a[i];
			sum[i] = sum[i-1] + a[i];
			ans[i] = 1;
		}
		for(int i=0;i<=5e4;i++) dp[i][0] = dp[i][1] = 0;
		for(int i=1;i<=n;i++) {
			dp[0][0] = i;
			for(int j=0;j<=5e4;j++) {
				dp[j][1] = max(dp[j][0],dp[j][1]);
				if(j + a[i] > (int)5e4) break;
				dp[j+a[i]][1] = max(dp[j][0],dp[j+a[i]][1]);
				dp[j][0] = dp[j][1];
				dp[j][1] = 0;
			}
			for(int l=1;l<=i;l++) {
				int x = sum[i] - sum[l-1];
				if(dp[x >> 1][0] < l || x % 2 == 1) ans[i - l + 1] = 0;
			}
		}
		vector<ll>res;
		for(int i=1;i<=n;i++) {
			if(ans[i]) res.pb(i);
		}
		cout<<res.size()<<" ";
		for(ll x: res) cout<<x<<" ";
		cout<<"\n";
	}
}
/*
1 2 2
2 3 1

*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...