답안 #631016

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
631016 2022-08-17T13:41:18 Z ZsofiaKeresztely Kpart (eJOI21_kpart) C++14
30 / 100
2000 ms 784 KB
#include <bits/stdc++.h>
using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t, n, s, sum, op;
  cin >> t;
  vector<int> a;
  vector<int> lasti;
  vector<bool> k;
  while (t--){
    cin >> n;
    a.resize(n);
    k.assign(n+1, true);
    k[0] = false;
    s = 0;
    for (int i=0; i<n; i++){
      cin >> a[i];
      s += a[i];
    }
    s /= 2;
    lasti.assign(s + 1, -1);
    for (int i=0; i<n; i++){
      for (int j=s-a[i]; j>0; j--){
        lasti[j + a[i]] = max(lasti[j + a[i]], lasti[j]);
      }
      if (a[i] <= s){
        lasti[a[i]] = i;
      }
      sum = 0;
      for (int j=i; j>=0; j--){
        sum += a[j];
        if (sum % 2 || lasti[sum / 2] < j){
          k[i - j + 1] = false;
        }
      }
    }
    op = 0;
    for (int x : k){
      if (x){
        op++;
      }
    }
    cout << op << " ";
    for (int i=1; i<n+1; i++){
      if (k[i]){
        cout << i << " ";
      }
    }
    cout << "\n";
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 340 KB Output is correct
2 Correct 28 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 178 ms 464 KB Output is correct
2 Correct 448 ms 540 KB Output is correct
3 Correct 540 ms 672 KB Output is correct
4 Correct 1012 ms 768 KB Output is correct
5 Execution timed out 2081 ms 784 KB Time limit exceeded
6 Halted 0 ms 0 KB -