답안 #1059818

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1059818 2024-08-15T08:27:11 Z MilosMilutinovic Kpart (eJOI21_kpart) C++14
100 / 100
1803 ms 1668 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 23 ms 560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 716 KB Output is correct
2 Correct 269 ms 1088 KB Output is correct
3 Correct 304 ms 844 KB Output is correct
4 Correct 536 ms 1352 KB Output is correct
5 Correct 1259 ms 1552 KB Output is correct
6 Correct 1803 ms 1604 KB Output is correct
7 Correct 1621 ms 1668 KB Output is correct