제출 #1167187

#제출 시각아이디문제언어결과실행 시간메모리
116718712345678Kpart (eJOI21_kpart)C++20
100 / 100
988 ms196196 KiB
#include <bits/stdc++.h>

using namespace std;

const int nx=1e3+5, kx=5e4+5;

int n, a[nx], qs[nx], dp[nx][kx], f[nx];

void solve()
{
    cin>>n;
    for (int i=1; i<=n; i++) cin>>a[i], qs[i]=qs[i-1]+a[i], f[i]=0;
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<kx; j++)
        {
            dp[i][j]=dp[i-1][j];
            if (j==a[i]) dp[i][j]=i;
            if (j>a[i]) dp[i][j]=max(dp[i][j], dp[i-1][j-a[i]]);
        }
        for (int j=i-1; j>=1; j--)
        {
            if ((qs[i]-qs[j-1])%2==0&&dp[i][(qs[i]-qs[j-1])/2]>=j);
            else f[i-j+1]=1;
        }
    }
    int cnt=0;
    for (int i=2; i<=n; i++) if (!f[i]) cnt++;
    cout<<cnt<<' ';
    for (int i=2; i<=n; i++) if (!f[i]) cout<<i<<' ';
    cout<<'\n';
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    int _t; cin>>_t;
    for (int i=0; i<kx; i++) dp[0][i]=-1;
    while (_t--) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...