#include <bits/stdc++.h>
using namespace std;
//bool dp[1005][50005];
unordered_set<int> dp[1005];
int v[1005];
int fr[1005];
signed main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int T; cin>>T; while(T--)
{
int n; cin>>n;
for(int i=1; i<=n; ++i)
{
cin>>v[i];
fr[i] = 0;
}
for(int i=1; i<=n; ++i)
{
int LIMIT = 50005;//min(50000, 200000/(n-i+1));
for(int j=0; j<=n-i+1; ++j)
// for(int k=0; k<=LIMIT; ++k)
// dp[j][k] = 0;
dp[j].clear();
// dp[0][0] = 1;
dp[0].insert(0);
for(int j=i; j<=n; ++j)
{
for(auto &k : dp[j-i])
{
if(k + v[j] <= LIMIT)
dp[j-i+1].insert(k + v[j]);
dp[j-i+1].insert(abs(k - v[j]));
}
if(dp[j-i+1].find(0) != dp[j-i+1].end())
++fr[j-i+1];
}
}
vector<int> ok;
for(int i=1; i<=n; ++i)
if(fr[i] == n - i + 1)
ok.push_back(i);
cout<<ok.size();
for(auto &i : ok) cout<<' '<<i;
cout<<'\n';
}
return 0;
}
/*
2
7
7 3 5 1 3 3 5
6
1 2 3 5 8 3
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |