제출 #1329034

#제출 시각아이디문제언어결과실행 시간메모리
1329034kawhietKpart (eJOI21_kpart)C++20
0 / 100
2095 ms480 KiB
#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> p(n + 1);
    for (int i = 0; i < n; i++) {
        p[i + 1] = p[i] + a[i];
    }
    auto good = [&](int k) {
        vector<int> s;
        for (int i = 0; i + k <= n; i++) {
            s.push_back(p[i + k] - p[i]);
            if (s.back() & 1) {
                return false;
            }
        }
        vector<bool> is(s[0] + 1);
        is[0] = 1;
        for (int i = 0; i < k; i++) {
            for (int j = s[0]; j >= a[i]; j--) {
                if (is[j - a[i]]) {
                    is[j] = 1;
                }
            }
        }
        if (!is[s[0] / 2]) return false;
        for (int i = 0; i + k < n; i++) {
            int out = a[i];
            int in = a[i + k];
            if (s[i] - out + in != s[i + 1]) {
                return false;
            }
        }
        return true;
    };
    vector<int> ans;
    for (int i = 1; i <= n; i++) {
        if (good(i)) {
            ans.push_back(i);
        }
    }
    cout << ans.size() << ' ';
    for (auto i : ans) {
        cout << i << ' ';
    }
    cout << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...