Submission #537538

# Submission time Handle Problem Language Result Execution time Memory
537538 2022-03-15T07:58:22 Z siewjh Kpart (eJOI21_kpart) C++17
30 / 100
2000 ms 172008 KB
#include <bits/stdc++.h>
using namespace std;
inline void read(int& x) {
    x = 0;
    char ch = getchar_unlocked();
    while (ch < '0' || ch > '9') ch = getchar_unlocked();
    while (ch >= '0' && ch <= '9') {
        x = (x << 3) + (x << 1) + (ch & 15);
        ch = getchar_unlocked();
    }
}
int main(){
    int cases; read(cases);
    while (cases--){
        int nums; read(nums);
        vector<int> vec(nums + 1), pref(nums + 1);
        pref[0] = 0;
        for (int i = 1; i <= nums; i++) read(vec[i]);
        for (int i = 1; i <= nums; i++) pref[i] = pref[i - 1] + vec[i];
        vector<vector<int>> dp(nums + 1, vector<int>(50005, -1));
        bitset<1005> notok;
        for (int i = 1; i <= nums; i++){
            for (int sum = 0; sum < vec[i]; sum++) dp[i][sum] = dp[i - 1][sum];
            for (int sum = vec[i]; sum < 50005; sum++) dp[i][sum] = max(dp[i - 1][sum], dp[i - 1][sum - vec[i]]);
            dp[i][vec[i]] = i;
        }
        for (int sz = 1; sz <= nums; sz++)
            for (int j = 1; j <= nums - sz + 1; j++){
                int i = j + sz - 1, sum = pref[i] - pref[j - 1];
                if (sum & 1) {
                    notok[sz] = 1;
                    break;
                }
                else if (dp[i][sum >> 1] < j) {
                    notok[sz] = 1;
                    break;
                }
            }
        int cnt = 0;
        for (int i = 1; i <= nums; i++)
            if (!notok[i])
                cnt++;
        cout << cnt << ' ';
        for (int i = 1; i <= nums; i++)
            if (!notok[i])
                cout << i << ' ';
        cout << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 46 ms 6516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 149 ms 13772 KB Output is correct
2 Correct 305 ms 23552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 621 ms 50740 KB Output is correct
2 Correct 1107 ms 75668 KB Output is correct
3 Correct 1061 ms 85496 KB Output is correct
4 Correct 1471 ms 110996 KB Output is correct
5 Execution timed out 2101 ms 172008 KB Time limit exceeded
6 Halted 0 ms 0 KB -