이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |