# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
538137 | jamielim | Kpart (eJOI21_kpart) | C++14 | 1620 ms | 197192 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,ii> i4;
const int MOD=1000000007;
const int INF=1012345678;
const ll LLINF=1012345678012345678LL;
const double PI=3.1415926536;
const double EPS=1e-14;
int t;
int n;
int arr[1005];
int pref[1005];
int dp[1005][50005];
// the latest start point so that at end point i you have a subsequence of sum j
int main(){
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&arr[i]);
pref[i]=pref[i-1]+arr[i];
}
memset(dp,-1,sizeof(dp));
for(int i=1;i<=n;i++){
dp[i][0]=i;
int m=min(pref[i],50005);
if(pref[i]<50005)dp[i][pref[i]]=1;
for(int j=1;j<m;j++){
dp[i][j]=dp[i-1][j];
if(j==arr[i])dp[i][j]=i;
if(j>arr[i])dp[i][j]=max(dp[i][j],dp[i-1][j-arr[i]]);
}
}
vector<int> ans;
for(int i=2;i<=n;i++){
bool poss=1;
for(int j=1;j<=n-i+1;j++){
int ttl=pref[j+i-1]-pref[j-1];
if(ttl%2==1){poss=0;break;}
if(dp[j+i-1][ttl/2]<j){poss=0;break;}
}
if(poss)ans.pb(i);
}
printf("%d ",SZ(ans));
for(int i:ans)printf("%d ",i);
printf("\n");
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |