답안 #537529

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537529 2022-03-15T07:46:58 Z siewjh Kpart (eJOI21_kpart) C++17
30 / 100
2000 ms 171908 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));
        vector<bool> ok(nums + 1, 1);
        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 j = 1; j <= i; j++){
                int sum = pref[i] - pref[j - 1], sz = i - j + 1;
                if (sum % 2) ok[sz] = 0;
                else if (dp[i][sum / 2] < j) ok[sz] = 0;
            }
        }
        int cnt = 0;
        for (int i = 1; i <= nums; i++)
            if (ok[i])
                cnt++;
        cout << cnt << ' ';
        for (int i = 1; i <= nums; i++)
            if (ok[i])
                cout << i << ' ';
        cout << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 6516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 172 ms 13772 KB Output is correct
2 Correct 301 ms 23620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 623 ms 50832 KB Output is correct
2 Correct 1066 ms 75676 KB Output is correct
3 Correct 1082 ms 85548 KB Output is correct
4 Correct 1509 ms 111444 KB Output is correct
5 Execution timed out 2082 ms 171908 KB Time limit exceeded
6 Halted 0 ms 0 KB -