Submission #537448

# Submission time Handle Problem Language Result Execution time Memory
537448 2022-03-15T06:17:59 Z joelau Kpart (eJOI21_kpart) C++14
10 / 100
2000 ms 2608 KB
#include <bits/stdc++.h>
using namespace std;

int T,N,A[1005], sum[1005];
bitset<1005> bs;
map<int,int> mp[2];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> T;
    while (T--) {
        cin >> N;
        sum[0] = 0;
        for (int i = 1; i <= N; ++i) {
            cin >> A[i];
            sum[i] = sum[i-1] + A[i];
        }
        bs.reset();
        for (int i = 1; i <= N; ++i) bs[i] = 1;
        mp[1].clear();
        mp[1][0] = 0;
        for (int i = 1; i <= N; ++i) {
            mp[0].clear();
            mp[0][0] = mp[0][A[i]] = i;
            for (auto x: mp[1]) mp[0][x.first] = max(mp[0][x.first],x.second), mp[0][x.first+A[i]] = max(mp[0][x.first+A[i]], x.second);
            for (int j = 1; j <= i; ++j) {
                int total = sum[i] - sum[j-1];
                if (total % 2 == 1 || mp[0][total/2] < j) bs[i-j+1] = 0;
            }
            swap(mp[0],mp[1]);
        }
        cout << bs.count();
        for (int i = 1; i <= N; ++i) if (bs[i]) cout << ' ' << i;
        cout << '\n';
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 76 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 655 ms 1008 KB Output is correct
2 Execution timed out 2067 ms 1568 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2076 ms 2608 KB Time limit exceeded
2 Halted 0 ms 0 KB -