Submission #1013684

# Submission time Handle Problem Language Result Execution time Memory
1013684 2024-07-03T20:24:59 Z _fractal Kpart (eJOI21_kpart) C++14
100 / 100
1194 ms 896 KB
#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define make_unique(x) sort(all(x)), x.erase(unique(all(x)), x.end())

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 Rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 1e3 + 20;
const int M = 1e5 + 20;
const int inf = 2e9 + 3;
const ll INF = 1e18;

int n;
int a[N];
int dp[M], is[N];

void solve() {
    cin >> n;
    fill(is + 1, is + n + 1, 1);
    fill(dp, dp + M, 0);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        for (int j = M - 1; j >= a[i]; --j)
           dp[j] = max(dp[j], dp[j - a[i]]);
        dp[0] = dp[a[i]] = i;
        for (int j = i, sum = 0; j >= 1; --j) {
            sum += a[j];
            if (sum % 2 == 1 || dp[sum / 2] < j)
                is[i - j + 1] = 0;
        }
    }
    cout << accumulate(is + 1, is + n + 1, 0) << '\n';
    for (int i = 1; i <= n; ++i)
        if (is[i]) 
            cout << i << " ";
    cout << '\n';
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int t;
    cin >> t;
    while (t--) solve();
    
}
# Verdict Execution time Memory Grader output
1 Correct 29 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 856 KB Output is correct
2 Correct 144 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 255 ms 860 KB Output is correct
2 Correct 453 ms 856 KB Output is correct
3 Correct 471 ms 860 KB Output is correct
4 Correct 683 ms 860 KB Output is correct
5 Correct 971 ms 860 KB Output is correct
6 Correct 1194 ms 856 KB Output is correct
7 Correct 1087 ms 896 KB Output is correct