#include <iostream>
#include <queue>
#include <set>
using namespace std;
vector<int> x, ans;
int N;
bool check(int l, int r, int sum) {
vector<int> dp(sum + 1, 0);
dp[0] = 1;
for (int i = l; i <= r; ++i) {
for (int j = sum; j >= 0; --j)
if (dp[j] != 0 && j + x[i] <= sum) {
dp[j + x[i]] = 1;
if (j + x[i] == sum) return true;
}
}
return false;
}
vector<int> solve() {
vector<int> A;
cin >> N;
x.assign(N + 1, 0);
for (int i = 1; i <= N; ++i) cin >> x[i];
for (int K = 2; K <= N; ++K) {
int sum = 0;
bool ok = true;
for (int i = 1; i <= K; ++i)
sum += x[i];
for (int i = K + 1; i <= N; ++i) {
if (sum % 2 != 0) {
ok = false;
break;
}
if (!check(i - K, i - 1, sum / 2)) {
ok = false;
break;
}
sum -= x[i - K];
sum += x[i];
}
if (sum % 2 == 1 || !check(N - K + 1, N, sum / 2)) ok = false;
if (ok) A.push_back(K);
}
return A;
}
int main()
{
int T;
cin >> T;
while (T--) {
ans = solve();
cout << ans.size() << ' ';
for (auto e : ans) cout << e << ' ';
cout << '\n';
ans.clear();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
422 ms |
332 KB |
Output is correct |
2 |
Execution timed out |
2087 ms |
440 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2076 ms |
424 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |