Submission #582584

# Submission time Handle Problem Language Result Execution time Memory
582584 2022-06-24T06:22:16 Z talant117408 Kpart (eJOI21_kpart) C++17
100 / 100
1139 ms 1100 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;
    vector <int> dp(100001, -1);
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = pref[i]; j >= v[i]; j--) {
            dp[j] = max(dp[j], dp[j-v[i]]);
        }
        dp[v[i]] = i;
        for (int j = i; j >= 1; j--) {
            int sum = pref[i]-pref[j-1];
            if (sum&1) ans[i-j+1] = 0;
            else if (dp[sum/2] < j) ans[i-j+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 2 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 716 KB Output is correct
2 Correct 22 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 724 KB Output is correct
2 Correct 187 ms 724 KB Output is correct
3 Correct 195 ms 832 KB Output is correct
4 Correct 388 ms 720 KB Output is correct
5 Correct 762 ms 772 KB Output is correct
6 Correct 1139 ms 916 KB Output is correct
7 Correct 953 ms 784 KB Output is correct