제출 #1059818

#제출 시각아이디문제언어결과실행 시간메모리
1059818MilosMilutinovicKpart (eJOI21_kpart)C++14
100 / 100
1803 ms1668 KiB
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    vector<long long> pref(n);
    for (int i = 0; i < n; i++) {
      pref[i] = (i == 0 ? 0LL : pref[i - 1]) + a[i];
    }
    int s = accumulate(a.begin(), a.end(), 0);
    vector<int> dp(s + 1, -1);
    vector<bool> ok(n + 1, true);
    for (int i = 0; i < n; i++) {
      vector<int> new_dp = dp;
      for (int j = 0; j + a[i] <= s; j++) {
        new_dp[j + a[i]] = max(new_dp[j + a[i]], dp[j]);
      }
      new_dp[a[i]] = i;
      swap(dp, new_dp); 
      for (int j = 1; j <= i + 1; j++) {
        int t = pref[i] - (i - j + 1 == 0 ? 0LL : pref[i - j]);
        if (t % 2 == 1 || dp[t / 2] <= i - j) {
          ok[j] = false;
        }
      }     
    }
    vector<int> res;
    for (int i = 1; i <= n; i++) {
      if (ok[i]) {
        res.push_back(i);
      }
    }
    cout << (int) res.size() << " ";
    for (int i : res) {
      cout << i << " ";
    }
    cout << '\n';
  }
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...