이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define maxa 100005
#define maxn 1005
int n,a[maxn],dp[maxa],pre[maxn];
bool check[maxn];
void solve(){
cin >> n;
for(int i=1;i<=n;i++){cin >> a[i];check[i]=true;pre[i]=pre[i-1]+a[i];}
int sum=0;dp[0]=maxn;
for(int j=1;j<=pre[n]/2;j++) dp[j]=0;
for(int i=1;i<=n;i++){
sum+=a[i];
for(int j=min(sum,pre[n]/2);j>=a[i];j--) dp[j]=max(dp[j],min(dp[j-a[i]],i));
for(int j=i;j>=1;j--){
int total=pre[i]-pre[j-1];
if(dp[total/2]<j || total%2==1) check[i-j+1]=false;
}
}
int num=0;
for(int i=1;i<=n;i++){
if(check[i]) num++;
}
cout << num << ' ';
for(int i=1;i<=n;i++){
if(check[i]) cout << i << ' ';
}
cout << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;cin >> t;
while(t--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |