답안 #537683

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537683 2022-03-15T11:22:23 Z siewjh Kpart (eJOI21_kpart) C++17
100 / 100
1033 ms 195900 KB
#include <bits/stdc++.h>
using namespace std;
int vec[1005], pref[1005], dp[1005][50005];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int cases; cin >> cases;
    while (cases--){
        int nums; cin >> nums;
        pref[0] = 0;
        for (int i = 1; i <= nums; i++) cin >> vec[i];
        for (int i = 1; i <= nums; i++) pref[i] = pref[i - 1] + vec[i];
        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 20 ms 6100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 13396 KB Output is correct
2 Correct 123 ms 23224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 234 ms 50400 KB Output is correct
2 Correct 414 ms 75388 KB Output is correct
3 Correct 411 ms 85084 KB Output is correct
4 Correct 647 ms 110700 KB Output is correct
5 Correct 840 ms 171500 KB Output is correct
6 Correct 1033 ms 193112 KB Output is correct
7 Correct 965 ms 195900 KB Output is correct