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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#include "xylophone.h"
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl "\n"
int mod=1e9+7;
int N=2e5+5;
template<class x>
using ordered_multiset = tree<x, null_type,less_equal<x>, rb_tree_tag,tree_order_statistics_node_update>;
int n,ttl,tmpttl;
vector<int> ans;
int v[3005];
int dp[20][3000];
int solve(int i,int sum) {
if (i==n+1) return abs(sum-abs(tmpttl-sum));
if (dp[i][sum]!=-1) return dp[i][sum];
int op1=solve(i+1,sum);
int op2=solve(i+1,sum+v[i]);
return dp[i][sum]=min(op1,op2);
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen(".in", "r", stdin); freopen(".out", "w", stdout);
cin>>n;
for (int i=0;i<n;i++) {
cin>>v[i];
ttl+=v[i];
}
for (int i=1;i<=3000;i++) {
v[n]=i; ttl++;
bool bl=true;
for (int j=0;j<=n;j++) {
memset(dp,-1,sizeof dp);
int tmp=v[j]; v[j]=0;
tmpttl=ttl-tmp;
int cl=solve(0,0);
v[j]=tmp;
if (cl!=0) {
bl=false; break;
}
}
if (bl) ans.push_back(i);
}
cout<<ans.size()<<endl;
for (int i:ans) cout<<i<<' ';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |