제출 #760787

#제출 시각아이디문제언어결과실행 시간메모리
760787bachhoangxuanKpart (eJOI21_kpart)C++17
100 / 100
585 ms716 KiB
#include <bits/stdc++.h>
using namespace std;
#define maxa 100005
#define maxn 1005
int n,a[maxn],dp[maxa],pre[maxn];
bool check[maxn];
void solve(){
    cin >> n;
    for(int i=1;i<=n;i++){cin >> a[i];check[i]=true;pre[i]=pre[i-1]+a[i];}
    int sum=0;dp[0]=maxn;
    for(int j=1;j<=pre[n]/2;j++) dp[j]=0;
    for(int i=1;i<=n;i++){
        sum+=a[i];
        for(int j=min(sum,pre[n]/2);j>=a[i];j--) dp[j]=max(dp[j],min(dp[j-a[i]],i));
        for(int j=i;j>=1;j--){
            int total=pre[i]-pre[j-1];
            if(dp[total/2]<j || total%2==1) check[i-j+1]=false;
        }
    }
    int num=0;
    for(int i=1;i<=n;i++){
        if(check[i]) num++;
    }
    cout << num << ' ';
    for(int i=1;i<=n;i++){
        if(check[i]) cout << i << ' ';
    }
    cout << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;cin >> t;
    while(t--) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...