제출 #1183738

#제출 시각아이디문제언어결과실행 시간메모리
1183738LilPlutonKpart (eJOI21_kpart)C++20
10 / 100
2095 ms504 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define ld long double
#define ar array
#define vc vector
#define aint(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define rep(i,a,b) for(int i = a; i < b; i++)
#define per(i,a,b) for(int i = a; i >= b; i--)
#define trav(a,x) for(auto& a : x)
#define sz(x) (int)(x).size()
#define ff first
#define ss second
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " = " << x << endl
const int N = 1e5 + 5;
const int L = 24;
const int inf = 1e9 + 7;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>


void solve(){
    int n;
    cin >> n;
    vc<int> a(n);
    rep(i, 0, n) cin >> a[i];
    vc<int>ans;
    for(int k = 2; k <= n; ++k) {
        bool ok = true;
        for(int i = 0; i + k - 1 < n; ++i) {
            vector<int> v(a.begin() + i, a.begin() + i + k); 
            int sum = accumulate(v.begin(), v.end(), 0LL);
            if(sum % 2 != 0) {
                ok = false;
                break;
            }
            bitset<N> dp; 
            dp[0] = 1;
            for(int num : v) {
                dp |= (dp << num);
            }
            if (!dp[sum / 2]) {
                ok = false;
                break;
            }
        }
        if(ok) {
            ans.push_back(k);
        }
    }
    cout << sz(ans) << ' ';
    for(int i = 0; i < sz(ans); ++i){
        cout << ans[i] << " ";
    }
    cout << endl;

}
 
signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
 
    int T = 1;
    cin >> T;
    while(T--){
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...