Submission #634999

# Submission time Handle Problem Language Result Execution time Memory
634999 2022-08-25T10:05:41 Z giorgikob Kpart (eJOI21_kpart) C++14
100 / 100
1714 ms 197284 KB
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define count1(x) __builtin_popcount(x)
#define endl '\n'
using namespace std;

const int N = 1e3+1, mod = 1e6, M = 5e4;

vector<int>pre(N+1, 0);
vector<vector<int>> ind(N+1, vector<int>(M+1, 0));

inline void test_case(){

    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        int x;
        cin >> x;
        pre[i] = pre[i-1] + x;
        for(int sum = 0; sum <= M; sum++){
            ind[i][sum] = ind[i-1][sum];
            if(sum == x){
                ind[i][sum] = i;
            } else if(sum > x){
                if(ind[i][sum] < ind[i-1][sum-x]){
                    ind[i][sum] = ind[i-1][sum-x];
                }
            }
        }
    }

    vector<int> ans;
    for(int k = 1; k <= n; k++){
        bool ok = true;
        for(int l = 1; l+k-1 <= n; l++){
            int r = l+k-1;
            int sum = pre[r] - pre[l-1];
            if(sum % 2 != 0 || ind[r][sum/2] < l){
                ok = false;
                break;
            }
        }
        if(ok){
            ans.pb(k);
        }
    }

    cout << ans.size() << " ";
    for(auto x : ans){
        cout << x << " ";
    }
    cout << endl;
}


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int T = 1;
    cin >> T;
    while(T--){
        test_case();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 102 ms 197196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 179 ms 197216 KB Output is correct
2 Correct 243 ms 197284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 428 ms 197176 KB Output is correct
2 Correct 612 ms 197192 KB Output is correct
3 Correct 679 ms 197272 KB Output is correct
4 Correct 991 ms 197184 KB Output is correct
5 Correct 1511 ms 197276 KB Output is correct
6 Correct 1714 ms 197256 KB Output is correct
7 Correct 1480 ms 197236 KB Output is correct