This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
const ll maxn = 1e5 + 1, maxm = 5e4 + 1, maxk = 61;
const ll inf = 1000000000, mod = inf + 7, mod2 = 998244353;
const ll pa = 31;
using namespace std;
int t, n;
int a[maxn], pref[maxn], pos[maxn];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> t;
while (t--){
cin >> n;
vector<int> ans;
for (int i = 1; i <= n; ++i){
cin >> a[i];
pref[i] = pref[i - 1] + a[i];
ans.pb(i);
}
for (int i = 0; i <= pref[n]; ++i){
pos[i] = -1;
}
pos[0] = 0;
for (int i = 1; i <= n; ++i){
for (int j = maxm - 1; j >= 0; --j){
if (pos[j] != -1 && j + a[i] <= maxm - 1){
pos[j + a[i]] = max(pos[j + a[i]], pos[j]);
}
}
pos[a[i]] = i;
vector<int> next;
for (auto it : ans){
if (it > i){
next.pb(it);
continue;
}
ll sum = pref[i] - pref[i - it];
if (sum % 2 == 0 && pos[sum / 2] >= i - it + 1){
next.pb(it);
}
}
ans = next;
}
cout << ans.size() << " ";
for (auto it : ans){
cout << it << " ";
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |