Submission #537449

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

int T,N,A[1005], sum[1005], dp[2][100005];
bitset<1005> bs;

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;
        memset(dp[1],-1,sizeof(dp[1]));
        dp[1][0] = 0;
        for (int i = 1; i <= N; ++i) {
            memset(dp[0],-1,sizeof(dp[0]));
            dp[0][0] = dp[0][A[i]] = i;
            for (int j = 0; j + A[i] <= sum[i]; ++j) dp[0][j] = max(dp[0][j],dp[1][j]), dp[0][j+A[i]] = max(dp[0][j+A[i]],dp[1][j]);
            for (int j = 1; j <= i; ++j) {
                int total = sum[i] - sum[j-1];
                if (total % 2 == 1 || dp[0][total/2] < j) bs[i-j+1] = 0;
            }
            swap(dp[0],dp[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 30 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 1108 KB Output is correct
2 Correct 206 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 413 ms 1108 KB Output is correct
2 Correct 763 ms 1224 KB Output is correct
3 Correct 853 ms 1108 KB Output is correct
4 Correct 1201 ms 1112 KB Output is correct
5 Execution timed out 2054 ms 1160 KB Time limit exceeded
6 Halted 0 ms 0 KB -