// author: erray
#include <bits/stdc++.h>
#ifdef DEBUG
#include "debug.h"
#else
#define debug(...) void(37)
#endif
using namespace std;
int main() {
ios_base::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<bool> ok(N, true);
vector<int> dp(1, -1);
int s = 1;
for (int i = 0; i < N; ++i) {
s += A[i];
dp.resize(s, -1);
for (int j = s - 1; j > A[i]; --j) {
dp[j] = max(dp[j], dp[j - A[i]]);
}
dp[A[i]] = i;
int sum = 0;
for (int j = i; j >= 0; --j) {
sum += A[j];
ok[i - j] = bool(ok[i - j]) && (sum % 2 == 0 && dp[sum / 2] >= j);
}
}
cout << accumulate(ok.begin(), ok.end(), 0) << '\n';
for (int i = 0; i < N; ++i) {
if (ok[i]) {
cout << i + 1 << ' ';
}
}
cout << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
324 KB |
Output is correct |
2 |
Correct |
16 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
612 KB |
Output is correct |
2 |
Correct |
168 ms |
788 KB |
Output is correct |
3 |
Correct |
188 ms |
976 KB |
Output is correct |
4 |
Correct |
332 ms |
1004 KB |
Output is correct |
5 |
Correct |
774 ms |
1360 KB |
Output is correct |
6 |
Correct |
1081 ms |
1544 KB |
Output is correct |
7 |
Correct |
995 ms |
1776 KB |
Output is correct |