Submission #1107376

# Submission time Handle Problem Language Result Execution time Memory
1107376 2024-11-01T07:22:31 Z vjudge1 Kpart (eJOI21_kpart) C++17
100 / 100
483 ms 4508 KB
/**
 *    hello
 *    author:  N29
 *    created: 2024-11-01 10:28:15
**/
#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#include<iostream>
#include<vector>

using namespace std;
#ifndef BADGNU
#pragma GCC target("sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#endif
#define static_assert(...);
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp> 
#include <tr2/dynamic_bitset>
// using namespace __gnu_pbds;
using namespace tr2;
#define ll long long
// #define int ll
#define ld long double
#define y1 cheza
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
// template<class T> using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
const int N=5e4+100;
const int M=1010;
const int B=447;
const int mod=998244353;
const ll INF=1e18;
const int dx[]={1,-1,0,0};
const int dy[]={0,0,1,-1};
const double eps=1e-6;
int n;
int a[M];
int pref[M];
dynamic_bitset<__uint128_t> kp;
bool bad[M];
int dp[M][M];
int f(int l,int r){
    if(l>r)return 0;
    if(dp[l][r]!=-1)return dp[l][r];
    if(l==r){
        dp[l][r]=0;
        return 0;
    }
    if((pref[r]-pref[l-1])%2){
        dp[l][r]=0;
        return dp[l][r];
    }
    for(int i=l;i<r;i++){
        if(f(l,i)+f(i+1,r)==2){
            dp[l][r]=1;
            return dp[l][r];
        }
    }
    
    kp.resize((pref[r]-pref[l-1])/2+2);
    kp.reset();
    kp[0]=1;
    for(int i=l;i<=r;i++){
        kp=(kp|kp<<a[i]);
    }
    dp[l][r]=kp[(pref[r]-pref[l-1])/2];
    return dp[l][r];
}
void test(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        bad[i]=0;
    }
    for(int i=1;i<=n;i++){
        pref[i]=pref[i-1]+a[i];
        for(int j=i;j<=n;j++){
            dp[i][j]=-1;
        }
    }
    for(int k=1;k<=n;k++){
        for(int i=1;i+k-1<=n;i++){
            f(i,i+k-1);
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j++){
            if(dp[i][j]==0){
                bad[(j-i+1)]=1;
            }
            // cout<<dp[i][j]<<' ';
        }
        // cout<<'\n';
    }
    vector<int>v;
    for(int i=1;i<=n;i++){
        if(bad[i])continue;
        v.push_back(i);
    }
    
    cout<<v.size()<<' ';
    for(auto i:v){
        cout<<i<<' ';
    }
    cout<<'\n';
    
}



/*

*/
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // cout.tie(nullptr);
    int t2=1;
    cin>>t2;
    for(int i=1;i<=t2;i++){
        test();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2640 KB Output is correct
2 Correct 14 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 2640 KB Output is correct
2 Correct 96 ms 2708 KB Output is correct
3 Correct 112 ms 2640 KB Output is correct
4 Correct 162 ms 2700 KB Output is correct
5 Correct 347 ms 3924 KB Output is correct
6 Correct 483 ms 4340 KB Output is correct
7 Correct 403 ms 4508 KB Output is correct