제출 #1280617

#제출 시각아이디문제언어결과실행 시간메모리
1280617bahaktlKpart (eJOI21_kpart)C++20
0 / 100
57 ms640 KiB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define int long long

const int N = 1e6+10;
const int inf = 1e18;

signed main() {         
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    int T;
    cin>>T;
    while(T--) {
        int n;
        cin>>n;
        int a[n+1];
        int pref[n+1];
        pref[0]=0;
        int ans[n+1];
        int x=0;
        for(int i=1;i<=n;i++) {
            cin>>a[i];
            pref[i]=pref[i-1]+a[i];
            ans[i]=1;
            x+=a[i];
        }
        int dp[pref[n]+1];
        dp[0]=0;
        for(int i=1;i<=n;i++) {
            for(int j=pref[n];j>=a[i];j--) {
                dp[j]=max(dp[j],dp[j-a[i]]);
            }
            dp[a[i]]=i;
            for(int j=1;j<=i;j++) {
                int sum=pref[i]-pref[j-1];
                if(sum%2==1) {
                    ans[i-j+1]=false;
                }
                ans[i-j+1] &= (dp[sum/2] >= j);
            }
        }
        vector<int>res;
        for(int i=1;i<n;i++) {
            if(a[i]!=a[i+1]) ans[2]=false;
        }
        for(int i=2;i<=n;i++) {
            if(ans[i]) res.pb(i);
        }
        cout<<res.size()<<' ';
        for(auto it:res) cout<<it<<' ';
        cout<<endl;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...