Submission #746581

# Submission time Handle Problem Language Result Execution time Memory
746581 2023-05-22T20:59:09 Z pascal Kpart (eJOI21_kpart) C++14
100 / 100
1377 ms 560 KB
#include <bits/stdc++.h>
using namespace std;

template <int MOD>
void compute(int N, const int A[], int out[])
{
    for (int deb = 0; deb < N; deb++)
    {
        bitset<MOD> S;
        S[0] = true;
        int somme = 0;
        for (int fin = deb; fin < N; fin++)
        {
            somme += A[fin];
            S = S | (S << (A[fin] % MOD) | S >> (MOD - (A[fin] % MOD)));
            if (somme % 2 == 1 || !S[(somme / 2) % MOD])
                out[fin - deb] = 1;
        }
    }
}

int main()
{
    int T;
    cin >> T;
    for (int i = 0; i < T; i++)
    {
        int N;
        cin >> N;
        int A[N];
        for (int i = 0; i < N; i++)
        {
            cin >> A[i];
        }
        int out[N] = {0};
        compute<1024>(N, A, out);
        compute<1023>(N, A, out);
        //  compute<1021>(N, A, out);
        /*
                for (int deb = 0; deb < N; deb++)
                {
                    bitset<1024> S;
                    S[0] = true;
                    int somme = 0;
                    for (int fin = deb; fin < N; fin++)
                    {
                        somme += A[fin];
                        S = S | (S << A[fin] | S >> (1024 - (A[fin] % 1024)));
                        if (somme % 2 == 1 || !S[(somme / 2) % 1024])
                            out[fin - deb] = 1;
                    }
                }*/
        int nb = 0;
        for (int i = 0; i < N; i++)
            if (out[i] == 0)
                nb++;
        cout << nb;
        for (int i = 0; i < N; i++)
            if (out[i] == 0)
                cout << " " << i + 1;
        cout << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 212 KB Output is correct
2 Correct 19 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 300 KB Output is correct
2 Correct 223 ms 296 KB Output is correct
3 Correct 230 ms 304 KB Output is correct
4 Correct 408 ms 340 KB Output is correct
5 Correct 963 ms 312 KB Output is correct
6 Correct 1377 ms 332 KB Output is correct
7 Correct 1234 ms 560 KB Output is correct