Submission #602566

# Submission time Handle Problem Language Result Execution time Memory
602566 2022-07-23T08:45:10 Z berr Kpart (eJOI21_kpart) C++17
30 / 100
2000 ms 26544 KB
#include <bits/stdc++.h>
using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int t; cin>>t; 
    while(t--)
    {
        int n; cin>>n;
        vector<int> pre(n), a(n), count(n+1);

        for(int i=0; i<n; i++)
        {
            cin>>a[i]; 
            if(i==0) pre[i]=a[i];
            else pre[i]=pre[i-1]+a[i];
        }
        set<int> q;

         
        vector<vector<int>> check(n, vector<int>(pre[n-1]+5, 0));
        vector<int> knp(pre[n-1]+5, -1);
 

        knp[0]=0;


        for(int i=0; i<n; i++)
        {
            for(int l=2; l<=i+1; l++)
            {
                int a=pre[i];
                if(i-l>=0) a-=pre[i-l];
                if(a%2==0)
                {
                    check[i][a/2]=l;
                }
            }
        }
        count[n]=1;

        for(int i=n-1; i>=0; i--)
        {
            count[i]=count[i+1]+1;

        }   


        for(int i=0; i<n; i++)
        {
            for(auto j: q)
            {
                int l=j*-1;
                if(knp[l]!=-1)
                {
                    knp[l+a[i]]=max(knp[l+a[i]], knp[l]);

                    if(check[i][l+a[i]]&&knp[l+a[i]]>=i-check[i][l+a[i]]+1)
                    {
                        count[check[i][l+a[i]]]--;
                    }
                    q.insert((l+a[i])*-1);
                }
            }
            knp[a[i]]=max(knp[a[i]], i);
            q.insert(a[i]*-1);
            if(check[i][a[i]]&&knp[a[i]]>=i-check[i][a[i]]+1)
            {
                count[check[i][a[i]]]--;
            }
           

        }

        vector<int> ans;
        for(int i=2; i<=n; i++)
        {
            if(count[i]==0) ans.push_back(i);
        }

        cout<<ans.size()<<" ";
        for(auto i: ans) cout<<i<<" ";
            cout<<"\n";


    }
   
}
# Verdict Execution time Memory Grader output
1 Correct 20 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 190 ms 2632 KB Output is correct
2 Correct 714 ms 7172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2073 ms 26544 KB Time limit exceeded
2 Halted 0 ms 0 KB -