#include<bits/stdc++.h>
using namespace std;
#define eb emplace_back
const int MX=50000;
int a[1005],qs[1005],dp[MX+5],Q,n,z,i,j,k;
int main(){
ios::sync_with_stdio(false);cin.tie(0);
cin>>Q;
while(Q--){
cin>>n;
z=0;
for(i=1;i<=n;++i){
cin>>a[i];
qs[i]=a[i]+qs[i-1];
if(a[i]>MX) z=1;
}
if(z) cout<<0<<endl;
else{
for(i=0;i<=MX;++i) dp[i]=0;
vector<int> ok(n+5,1),ans;
for(i=1;i<=n;++i){
for(j=MX-a[i];j>=1;--j) if(dp[j]) dp[j+a[i]]=max(dp[j+a[i]],dp[j]);
dp[a[i]]=i;
for(j=1,k=i;j<i;++j,--k){
if((qs[i]-qs[j-1])&1) ok[k]=0;
else if(dp[qs[i]-qs[j-1]>>1]<j) ok[k]=0;
}
}
for(i=2;i<=n;++i) if(ok[i]) ans.eb(i);
cout<<ans.size()<<" ";
for(auto &e:ans) cout<<e<<" ";
cout<<endl;
}
}
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:26:22: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
26 | else if(dp[qs[i]-qs[j-1]>>1]<j) ok[k]=0;
| ~~~~~^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
856 KB |
Output is correct |
2 |
Correct |
73 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
150 ms |
856 KB |
Output is correct |
2 |
Correct |
262 ms |
600 KB |
Output is correct |
3 |
Correct |
270 ms |
604 KB |
Output is correct |
4 |
Correct |
390 ms |
652 KB |
Output is correct |
5 |
Correct |
604 ms |
864 KB |
Output is correct |
6 |
Correct |
755 ms |
680 KB |
Output is correct |
7 |
Correct |
698 ms |
600 KB |
Output is correct |