답안 #632501

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
632501 2022-08-20T08:12:19 Z ZsofiaKeresztely Kpart (eJOI21_kpart) C++14
30 / 100
2000 ms 560 KB
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int t, n, s, sum, op;
  cin >> t;
  while (t--){
    cin >> n;
    vector<int> a(n + 1);
    vector<bool> k(n + 1);
    s = a[0] = k[0] = 0;
    for (int i=1; i<n+1; i++){
      cin >> a[i];
      s += a[i];
      k[i] = true;
    }
    s /= 2;
    vector<int> lasti(s + 1, 0);
    for (int i=1; i<n+1; 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 13 ms 212 KB Output is correct
2 Correct 46 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 174 ms 388 KB Output is correct
2 Correct 450 ms 468 KB Output is correct
3 Correct 543 ms 496 KB Output is correct
4 Correct 925 ms 560 KB Output is correct
5 Execution timed out 2087 ms 560 KB Time limit exceeded
6 Halted 0 ms 0 KB -