Submission #637901

# Submission time Handle Problem Language Result Execution time Memory
637901 2022-09-03T14:22:44 Z ksu2009en Kpart (eJOI21_kpart) C++17
30 / 100
154 ms 580 KB
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2")

#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>
#include <cstring>

#define endl '\n'

using namespace std;
typedef int ll;

bitset<10007>bs;


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    ll t;
    cin >> t;
    
    while(t--){
        ll n;
        cin >> n;
        
        vector<ll>a(n);
        for(int i = 0; i < n; i++)
            cin >> a[i];
        
        vector<vector<ll>>can(n + 1, vector<ll>(n + 1));
        
        for(int i = 0; i < n; i++){
            bs = 0;
            
            bs[a[i]] = 1;
            ll sum = a[i];
            
            for(int j = i + 1; j < n; j++){
                sum += a[j];
                
                bs |= (bs << a[j]);
                bs[a[j]] = 1;
                
                if(sum % 2 == 0 && bs[sum / 2])
                    can[i][j - i + 1] = 1;
            }
        }
        /*
        for(int i = 0; i < n; i++){
            for(int j = 0; j <= n; j++)
                cout << can[i][j] << ' ';
            cout << endl;
        }
         */
        
        vector<ll>ans;
        for(int j = 2; j <= n; j++){
            bool ok = false;
            
            for(int i = 0; i < n; i++){
                if(i + j - 1 >= n)
                    continue;
                
                if(!can[i][j])
                    ok = true;
            }
            
            if(!ok)
                ans.push_back(j);
        }
        cout << ans.size() << ' ';
        
        for(auto i: ans)
            cout << i << ' ';
        cout << endl;
        
        /*
        if(ans != slow(n, a)){
            cout << n << endl;
            for(auto i: a)
                cout << i << ' ';
            cout << endl;
            
            
            for(auto i: ans)
                cout << i << ' ';
            cout << endl;
            
            auto y = slow(n, a);
            for(auto i: y)
                cout << i << ' ';
            cout << endl;
            
            return 0;
        }
         */
    }
    
    return 0;
}
/*
 1
 10
 28 23 18 28 83 22 79 64 80 33
 
 */
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 340 KB Output is correct
2 Correct 35 ms 388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 154 ms 580 KB Output isn't correct
2 Halted 0 ms 0 KB -