답안 #913998

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
913998 2024-01-20T17:59:46 Z MisterReaper Kpart (eJOI21_kpart) C++17
100 / 100
861 ms 1720 KB
#include <bits/stdc++.h>
using i64 = long long;

#define ONLINE_JUDGE
void solve() {
    int n;
    std::cin >> n;

    std::vector<int> a(n + 1);
    for(int i = 1; i <= n; i++) {
        std::cin >> a[i];
    }

    int sum = 0;
    std::vector<int> dp(1), ans(n + 1, true);
    for(int i = 1; i <= n; i++) {
        sum += a[i];
        dp.resize(sum + 1, -1);
        for(int j = sum; j >= a[i]; j--) {
            dp[j] = std::max(dp[j], dp[j - a[i]]);
        }
        dp[a[i]] = i;

        /*
        for(int i = 0; i <= sum; i++) {
            std::cerr << dp[i] << " \n"[i == sum];
        }
        */

        int ssum = 0;
        for(int j = i; j >= 1; j--) {
            ssum += a[j];
            ans[i - j + 1] &= (ssum % 2 == 0 && dp[ssum / 2] >= j);
        }
    }

    std::vector<int> pr;
    for(int i = 1; i <= n; i++) {
        if(ans[i]) {
            pr.emplace_back(i);
        }
    }

    std::cout << int(pr.size()) << " ";
    for(int &i : pr) {
        std::cout << i << " ";
    }
    std::cout << "\n";
    
    return;
}

signed main() {
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif

    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL); std::cout.tie(NULL);

    int t = 1; std::cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 13 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 724 KB Output is correct
2 Correct 128 ms 920 KB Output is correct
3 Correct 151 ms 944 KB Output is correct
4 Correct 275 ms 1184 KB Output is correct
5 Correct 612 ms 1464 KB Output is correct
6 Correct 861 ms 1584 KB Output is correct
7 Correct 776 ms 1720 KB Output is correct