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>
#define suiii ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define co cout<<
//#pragma GCC optimize("O3,Ofast,unroll-loops")
//#pragma GCC target("avx2,sse3,sse4,avx")
using namespace std;
//stuff
int vis[105][10005];
int arr[105];
ll skipped;
int ans=0;
int n,wholesum=0;
map<int,int>mp;
ll sum=0;
void rec(int x){
if(vis[x][sum]||ans) return;
if(skipped==x){
rec(x+1);
return;
}
if(x==n+1){
if(sum==wholesum-sum) ans=1;
return;
}
vis[x][sum]=1;
if(x==n){
ll k=wholesum-sum;
mp[abs(sum-k)]++;
return;
}
sum+=arr[x];
rec(x+1);
sum-=arr[x];
rec(x+1);
}
void solve(){
cin>>n;
for(int i=0;i<n;i++){
cin>>arr[i];
wholesum+=arr[i];
}
skipped=n;
rec(0);
if(ans==0){
co 0;
return;
}
ans=0;
vector<int>answers;
for(int i=0;i<n;i++){
memset(vis,0,sizeof(vis));
wholesum-=arr[i];
skipped=i;
rec(0);
wholesum+=arr[i];
}
for(auto i:mp){
if(i.first<1) continue;
if(i.second/2==n) answers.push_back(i.first);
}
co answers.size()<<'\n';
for(auto i:answers) co i<<' ';
}
int main()
{
suiii
int t=1;
// cin>>t;
while(t--){
solve();
}
return 0;
}
# | 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... |