Submission #582536

# Submission time Handle Problem Language Result Execution time Memory
582536 2022-06-24T04:27:26 Z talant117408 Kpart (eJOI21_kpart) C++17
30 / 100
2000 ms 364 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#define long                unsigned long 
#define pb                  push_back
#define mp                  make_pair
#define all(v)              (v).begin(),(v).end()
#define rall(v)             (v).rbegin(),(v).rend()
#define lb                  lower_bound
#define ub                  upper_bound
#define sz(v)               int((v).size())
#define do_not_disturb      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl                '\n'
#define PI                  2*acos(0.0)

void solve() {
    int n;
    cin >> n;
    vector <int> v(n+1), pref(n+1);
    for (int i = 1; i <= n; i++) {
        cin >> v[i];
        pref[i] = pref[i-1] + v[i];
    }
    bitset <1001> ans;
    for (int i = 1; i <= n; i++) ans[i] = 1;
    for (int i = 1; i <= n; i++) {
        bitset <50001> dp;
        dp[0] = 1;
        for (int j = i; j <= n; j++) {
            dp |= (dp << v[j]);
            if ((pref[j]-pref[i-1])&1 || dp[(pref[j]-pref[i-1])/2] == 0) {
                ans[j-i+1] = 0;
            }
        }
    }
    
    vector <int> K;
    for (int i = 2; i <= n; i++) {
        if (ans[i]) K.pb(i);
    } 
    cout << sz(K) << ' ';
    for (auto to : K) cout << to << ' ';
    cout << endl;
}

int main() {
    do_not_disturb
    
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    
    return 0;
}
/*

*/
# Verdict Execution time Memory Grader output
1 Correct 7 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 328 KB Output is correct
2 Correct 176 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 765 ms 328 KB Output is correct
2 Correct 1967 ms 336 KB Output is correct
3 Execution timed out 2084 ms 364 KB Time limit exceeded
4 Halted 0 ms 0 KB -