Submission #839652

# Submission time Handle Problem Language Result Execution time Memory
839652 2023-08-30T11:27:21 Z alishejhf Kpart (eJOI21_kpart) C++14
100 / 100
1749 ms 196168 KB
#include<bits/stdc++.h>

#define ent '\n'
#define fi first
#define se second
#define sz(x) (int)x.size()
#define pb push_back
#define all(x) x.begin(),x.end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int N = 1e3 + 10;
const int mod = 1e9 + 7;
const int inf = (int)(1e9 + 7);
const ll INF = (ll)(2e18 + 7);
const ld eps = (ld)(1e-12);
const int dx[] = { -1,0,1,0,1,1,-1,-1 }, dy[] = { 0,1,0,-1,1,-1,1,-1 };
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
int n,a[N],dp[N][50010],cnt[N];
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        cnt[i]=0;
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=5e4;j++){
            dp[i][j]=0;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<=5e4;j++){
            dp[i][j]=max(dp[i][j],dp[i-1][j]);
            if(j+a[i]<=5e4){
                if(!j){
                    dp[i][j+a[i]]=max(dp[i][j+a[i]],i);
                }
                else{
                    dp[i][j+a[i]]=max(dp[i][j+a[i]],dp[i-1][j]);
                }
            }
        }
    }
    for(int i=1;i<=n;i++){
        ll sum=0;
        for(int j=i;j<=n;j++){
            sum+=a[j];
            if(sum&1) continue;
            if(i<=dp[j][sum>>1]){
                cnt[j-i+1]++;
            }
        }
    }
    vector<int> ans;
    for(int i=1;i<=n;i++){
        if(cnt[i]==n-i+1){
            ans.pb(i);
        }
    }
    cout<<sz(ans)<<' ';
    for(auto it:ans){
        cout<<it<<' ';
    }
    cout<<ent;
    return;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    srand(time(0));
    //freopen(".in", "r", stdin);
    //freopen(".out","w",stdout);
    int ttt=1;
    cin>>ttt;
    for(int i=1;i<=ttt;i++){
        //cout<<"NEWCASE"<<ent;
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 31 ms 6376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 13652 KB Output is correct
2 Correct 196 ms 23360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 383 ms 50620 KB Output is correct
2 Correct 660 ms 75472 KB Output is correct
3 Correct 684 ms 85324 KB Output is correct
4 Correct 939 ms 110860 KB Output is correct
5 Correct 1449 ms 171688 KB Output is correct
6 Correct 1749 ms 193136 KB Output is correct
7 Correct 1632 ms 196168 KB Output is correct