#include <bits/stdc++.h>
using namespace std;
int check[1005][100015];
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
int t; cin>>t;
int p=0;
while(t--)
{
int n; cin>>n;
vector<int> pre(n), a(n), count(n+1);
for(int i=0; i<n; i++)
{
cin>>a[i];
if(i==0) pre[i]=a[i];
else pre[i]=pre[i-1]+a[i];
}
vector<int> knp(pre[n-1]+5, -1);
knp[0]=0;
for(int i=0; i<n; i++)
{
for(int l=2; l<=i+1; l++)
{
int a=pre[i];
if(i-l>=0) a-=pre[i-l];
if(a%2==0)
{
check[i][a/2]=l+p;
}
}
}
count[n]=1;
for(int i=n-1; i>=0; i--)
{
count[i]=count[i+1]+1;
}
for(int i=0; i<n; i++)
{
set<int> s;
for(int l=pre[n-1]/2; l>0; l--)
{
if(knp[l]!=-1)
{
knp[l+a[i]]=max(knp[l+a[i]], knp[l]);
if(check[i][l+a[i]]>p&&knp[l+a[i]]>=i-(check[i][l+a[i]]-p)+1)
{
count[check[i][l+a[i]]-p]--;
}
}
}
knp[a[i]]=max(knp[a[i]], i);
if(check[i][a[i]]>p&&knp[a[i]]>=i-(check[i][a[i]]-p)+1)
{
count[check[i][a[i]]-p]--;
}
for(auto j: s) count[j]--;
}
vector<int> ans;
for(int i=2; i<=n; i++)
{
if(count[i]==0) ans.push_back(i);
}
cout<<ans.size()<<" ";
for(auto i: ans) cout<<i<<" ";
cout<<"\n";
p+=n+3;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1236 KB |
Output is correct |
2 |
Correct |
42 ms |
2596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
166 ms |
8508 KB |
Output is correct |
2 |
Correct |
451 ms |
17848 KB |
Output is correct |
3 |
Correct |
525 ms |
22376 KB |
Output is correct |
4 |
Correct |
958 ms |
36388 KB |
Output is correct |
5 |
Execution timed out |
2052 ms |
84276 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |