Submission #1209918

#TimeUsernameProblemLanguageResultExecution timeMemory
1209918sunflowerKpart (eJOI21_kpart)C++17
30 / 100
2093 ms488 KiB
#include <bits/stdc++.h>
using namespace std;

int n;

#define MAX_N 100'100
int a[1'010], cnt[1'010];
short res[1'010];
bitset <MAX_N + 2> bs;

int main() {
  ios_base::sync_with_stdio(false);cin.tie(nullptr);
  // freopen("test.inp","r",stdin);
  // freopen("test.out","w",stdout);

  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];

    memset(cnt, 0, (n + 2) * sizeof(int));
    for (int i = 1; i <= n; ++i) {
      bs.reset();
      int sum = 0;
      bs[0] = 1;
      for (int j = i; j <= n; ++j) {
        sum += a[j];
        bs |= (bs << a[j]);

        if (sum % 2 == 0 && bs[sum >> 1]) cnt[j - i + 1]++;
      }
    }

    int size_res = 0;
    for (int i = 1; i <= n; ++i) {
      if (cnt[i] == n - i + 1) res[++size_res] = i;
    }

    cout << size_res << " ";
    for (int i = 1; i <= size_res; ++i) cout << res[i] << " ";
    cout << "\n";
  }

  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...