이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ull unsigned ll
#define pb push_back
#define epb emplace_back
#define inf 1e9+1
#define linf 1e18+1
using namespace std;
int dp[1001][50001];
int pref[1001];
void solve(){
int n;cin>>n;
int a[n+1];
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=0;i<=n;i++){
for(int j=0;j<=50000;j++)dp[i][j]=-1;
pref[i]=0;
}
for(int i=1;i<=n;i++){
pref[i]=pref[i-1]+a[i];
}
dp[0][0]=0;
for(int i=1;i<=n;i++){
for(int j=50000;j>=1;j--){
dp[i][j]=dp[i-1][j];
if(j>a[i])dp[i][j]=max(dp[i-1][j-a[i]],dp[i][j]);
if(j==a[i])dp[i][j]=i;
}
}
vector<int>ans;
for(int i=2;i<=n;i++){
bool ind=true;
for(int j=i;j<=n;j++){
int sum=pref[j]-pref[j-i];
if(sum&1){
ind=false;
break;
}
if(dp[j][sum/2]<=j-i){
ind=false;
break;
}
}
if(ind)ans.pb(i);
}
cout<<ans.size()<<" ";
for(int to:ans)cout<<to<<' ';
cout<<"\n";
}
int main(){
int test=1;cin>>test;
while(test--)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... |