Submission #1089316

# Submission time Handle Problem Language Result Execution time Memory
1089316 2024-09-16T09:51:33 Z vjudge1 Kpart (eJOI21_kpart) C++17
10 / 100
706 ms 949272 KB
#include <bits/stdc++.h>
//qwerty47924692
using namespace std;
using ll = int;
const ll N=1e5+29;
ll n,t,a[N],dp[35][35][N],pref[N];

void solve(){
    cin>>n;
    for(ll l=1;l<=n;l++){
        for(ll r=1;r<=n;r++){
            for(ll i=1;i<N;i++){
                dp[l][r][i]=0;
            }
        }
    }
    for(ll i=1;i<=n;i++){
        cin>>a[i];
        pref[i]=pref[i-1]+a[i];
    }
    dp[0][0][0]=1;
    for(ll l=1;l<=n;l++){
        dp[l][l-1][0]=1;
        for(ll r=l;r<=n;r++){
            for(ll w=a[r];w<N;w++){
                dp[l][r][w]=0;
                dp[l][r][w]|=dp[l][r-1][w-a[r]];
                dp[l][r][w]|=dp[l][r-1][w];
            }
            for(ll w=0;w<a[r];w++){
                dp[l][r][w]|=dp[l][r-1][w];
            }
        }
    }
    vector<ll>v;

    for(ll k=2;k<=n;k++){
        ll ch=1;

        for(ll i=1;i+k-1<=n;i++){
            ll pr=pref[i-1];
            ll sum=pref[i+k-1]-pref[i-1];
            if(dp[i][i+k-1][sum/2]&&(!(sum&1))){
                continue;
            }
            else ch=0;


        }if(ch)v.push_back(k);

    }
   // cout<<dp[1][4][8]<<' ';
    cout<<v.size();

    for(ll i:v){
        cout<<' '<<i;
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll t;

    cin>>t;
    while(t--){
        solve();
        cout<<'\n';
    }
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:41:16: warning: unused variable 'pr' [-Wunused-variable]
   41 |             ll pr=pref[i-1];
      |                ^~
# Verdict Execution time Memory Grader output
1 Correct 706 ms 356872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 515 ms 949272 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 679 ms 949056 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -