답안 #605681

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
605681 2022-07-25T22:25:20 Z Urvuk3 Kpart (eJOI21_kpart) C++17
0 / 100
667 ms 18640 KB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
ll INF=1e9,LINF=1e18,MOD=1e9+7; const ll MAXN=1e3+1,MAXA=5e4;
#define fi first
#define se second
#define pii pair<int,int>
#define mid ((l+r)/2)
#define sz(a) (int((a).size()))
#define all(a) a.begin(),a.end()
#define endl "\n"
#define PRINT(x) cerr<<#x<<'-'<<x<<endl<<flush;
#define pb push_back
#define PRINTvec(x) { cerr<<#x<<"-"; for(auto h:x) cerr<<h<<" "; cerr<<endl; }

int a[MAXN],dp[MAXN][MAXA+1],pref[MAXN];

void Solve(){
    int N; cin>>N;
    for(int i=1;i<=N;i++){
        cin>>a[i];
        pref[i]=a[i]+pref[i-1];
    }
    fill(dp[1],dp[1]+MAXA+1,0);
    //dp[1][a[1]]=1;
    unordered_set<int> s; s.max_load_factor(0.25);s.reserve(65536);
    s.insert(0);
    //if(a[1]<=MAXA) s.insert(a[1]);
    for(int i=1;i<=N;i++){
        /*
        for(int A=0;A<=MAXA;A++){
            //PRINT(i); PRINT(A);
            dp[i][A]=dp[i-1][A];
            if(A>a[i]) dp[i][A]=max(dp[i][A],dp[i-1][A-a[i]]);
            else if(A==a[i]) dp[i][A]=i;
        }
        */
        vector<int> so;
        for(auto x:s){
            int x1=x,x2=x+a[i];
            dp[i][x1]=max(dp[i][x1],dp[i-1][x1]);
            if(x2<=MAXA){
                so.pb(x2);
                dp[i][x2]=max(dp[i][x2],dp[i-1][x1]);
                if(x2==a[i]) dp[i][x2]=i;
            }
        }
        for(auto x:so) s.insert(x);
        //PRINT(i); PRINTvec(s);
    }
    vector<int> ans;
    for(int K=2;K<=N;K++){
        bool ok=true;
        for(int l=1;l+K-1<=N;l++){
            int r=l+K-1;
            int sum=pref[r]-pref[l-1];
            ok&=(sum%2==0 && dp[r][sum/2]>=l);
        }
        if(ok) ans.pb(K);
    }
    cout<<sz(ans)<<" ";
    for(auto x:ans){
        cout<<x<<" ";
    }
    cout<<endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    //t=1;
    while(t--){
        Solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 3164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 54 ms 4352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 667 ms 18640 KB Output isn't correct
2 Halted 0 ms 0 KB -