Submission #634995

# Submission time Handle Problem Language Result Execution time Memory
634995 2022-08-25T10:03:22 Z giorgikob Kpart (eJOI21_kpart) C++14
100 / 100
1595 ms 197452 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 && 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 103 ms 197164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 153 ms 197168 KB Output is correct
2 Correct 225 ms 197232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 357 ms 197196 KB Output is correct
2 Correct 635 ms 197184 KB Output is correct
3 Correct 632 ms 197196 KB Output is correct
4 Correct 902 ms 197264 KB Output is correct
5 Correct 1273 ms 197256 KB Output is correct
6 Correct 1595 ms 197256 KB Output is correct
7 Correct 1435 ms 197452 KB Output is correct