Submission #1062775

# Submission time Handle Problem Language Result Execution time Memory
1062775 2024-08-17T10:39:27 Z armashka Kpart (eJOI21_kpart) C++17
0 / 100
795 ms 472 KB
#include<bits/stdc++.h>

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file(s) freopen(s".in", "r", stdin);freopen(s".out", "w", stdout);
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ft first
#define sd second
#define ll long long
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
const int N = 1e6 + 10;
const int M = 1e6 + 5;
const int B = 316;
const ll msize = 2;
const ll mod1 = 1e9 + 7;
const ll mod2 = 998244353;
const long double Phi = acos(-1);
const long long inf = 2e9;
const vector <pair<int, int>> dir = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

ll binmul(ll x, ll ti, ll m);
ll binpow(ll x, ll ti, ll m);

ll n, a[1005], pref[1005];
bitset<100005> bt;
bitset<1005> ans;

const void solve() {
    cin >> n;
    for (int i = 1; i <= n; ++ i) cin >> a[i], pref[i] = pref[i - 1] + a[i];

    ans.reset();
    ans[0] = 1;
    for (int k = 2; k <= n; ++ k) {
        if (ans[k]) continue;
        int l = 1, r = k;

        bt.reset();
        bt[0] = 1;
        for (int i = l; i <= r; ++ i) bt |= (bt << a[i]);

        bool ok = true;
        while (r <= n) {
            ll sum = pref[r] - pref[l - 1];
            if (sum % 2 == 0) {

                // if (k == 8) {
                //     for (int i = 0; i <= 40; ++ i) cout << bt[i];
                //     cout <<"\n";
                // }

                // bt.reset();
                // bt[0] = 1;
                // for (int i = l; i <= r; ++ i)
                //     bt |= (bt << a[i]);

                if (bt[sum / 2] == 0) {
                    ok = 0;
                    break;
                }

            } else {
                ok = 0;
                break;
            }
            ++ l; ++ r;

            bt ^= (bt << a[l - 1]);
            bt |= (bt << a[r]);
        }
        if (ok) {
            for (int i = 1; i <= n / k; ++ i) ans |= (ans << k);
        }
    }

    vector <ll> res;
    for (int i = 1; i <= n; ++ i)
        if (ans[i]) res.pb(i);

    cout << res.size() << " ";
    for (auto x : res) cout << x << " ";
    cout << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    srand(time(NULL));

    // file("promote");

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tt = 1;
    cin >> tt;
    for (int i = 1; i <= tt; ++ i) {
        // cout << "Caso #" << i << "\n";
        // n = i;
        solve();
    }

    #ifndef ONLINE_JUDGE
    cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif

    return 0;
}


// Template functions
ll binmul(ll x, ll ti, ll m) { ll res = 0;while (ti){if(ti & 1)res += x;x += x;ti >>= 1; x %= m; res %= m;} return res;}
ll binpow(ll x, ll ti, ll m) { ll res = 1;while (ti){if(ti & 1)(res *= x)%=m;(x*=x)%=m;ti >>= 1; x %= m; res %= m;} return res;}
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 795 ms 472 KB Output isn't correct
2 Halted 0 ms 0 KB -