Submission #792533

# Submission time Handle Problem Language Result Execution time Memory
792533 2023-07-25T06:30:33 Z otarius Kpart (eJOI21_kpart) C++17
100 / 100
487 ms 608 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
 
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair <int, int>
#define ull unsigned long long
 
// #define int long long
// #define int unsigned long long
 
const ll inf = 1e9 + 7;
const ll weirdMod = 998244353;
 
void solve() {
    int n;
    cin >> n;
    int arr[n + 1], pref[n + 1]; pref[0] = 0;
    for (int i = 1; i <= n; i++) {
        cin >> arr[i]; pref[i] = arr[i] + pref[i - 1];
    } int sum = pref[n], dp[sum / 2 + 5], cur;
    for (int j = 0; j <= sum / 2; j++) dp[j] = 0;
    bool good[n + 1] = {};
    for (int i = 1; i <= n; i++) good[i] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = min(pref[i], sum / 2); j > arr[i]; j--)
            dp[j] = max(dp[j], dp[j - arr[i]]);
        dp[arr[i]] = i;
        for (int j = i; j >= 1; j--) {
            cur = pref[i] - pref[j - 1];
            if (cur % 2 == 1 || dp[cur / 2] < j)
                good[i - j + 1] = 0;
        }
    } int num = 0;
    for (int i = 1; i <= n; i++)
        num += good[i];
    cout << num << ' ';
    for (int i = 1; i <= n; i++)
        if (good[i]) cout << i << ' ';
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    } return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 212 KB Output is correct
2 Correct 7 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 388 KB Output is correct
2 Correct 74 ms 412 KB Output is correct
3 Correct 87 ms 432 KB Output is correct
4 Correct 153 ms 468 KB Output is correct
5 Correct 354 ms 556 KB Output is correct
6 Correct 487 ms 608 KB Output is correct
7 Correct 447 ms 588 KB Output is correct