이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t, n, s;
cin >> t;
vector<int> a, lasti, pref;
set<int> k;
while (t--){
cin >> n;
a.assign(n+1, 0);
lasti.assign(50001, -1);
pref.assign(n+1, 0);
k.clear();
s = 0;
for (int i=1; i<n+1; i++){
cin >> a[i];
s += a[i];
pref[i] = s;
}
s /= 2;
for (int i=1; i<n+1; i++){
k.insert(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;
}
auto cur = k.begin();
for (auto it = k.begin(); it != k.end();){
cur = it++;
if ((pref[i] - pref[i - *cur]) % 2 || lasti[(pref[i] - pref[i - *cur]) / 2] < i - *cur + 1){
k.erase(cur);
}
}
}
cout << k.size() << " ";
for (int x : k){
cout << x << " ";
}
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... |