Submission #746579

# Submission time Handle Problem Language Result Execution time Memory
746579 2023-05-22T20:56:36 Z pascal Kpart (eJOI21_kpart) C++14
100 / 100
1338 ms 484 KB
#include <bits/stdc++.h>
using namespace std;

template <int MOD>
void compute(int N, const int A[], int out[])
{
    bitset<MOD> S;

    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] % 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 8 ms 212 KB Output is correct
2 Correct 18 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 304 KB Output is correct
2 Correct 213 ms 328 KB Output is correct
3 Correct 241 ms 440 KB Output is correct
4 Correct 412 ms 328 KB Output is correct
5 Correct 988 ms 484 KB Output is correct
6 Correct 1338 ms 340 KB Output is correct
7 Correct 1292 ms 372 KB Output is correct