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 <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define int long long
using namespace std;
const long long oo = 1000000000000000000;
long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
/*
ViHHiPuh
(( `'-""``""-'` ))
)-__-_.._-__-(
/ --- (o _ o) --- \
\ .-* ( .0. ) *-. /
_'-. ,_ '=' _, .-'_
/ `;#'#'# - #'#'#;` \
\_)) -----'#'----- ((_/
# --------- #
'# ------- ------ #'
/..-'# ------- #'-.\
_\...-\'# -- #'/-.../_
((____)- '#' -(____))
cout << fixed << setprecision(6) << x;
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
freopen ( "sum.in", "r", stdin )
*/
int n, a[ 10001 ], dp[ 2500001 ], mp[ 2500001 ], mpp[ 2500001 ];
vector <int> v;
int mod = 1e9 + 7;
main () {
cin >> n;
dp[ 0 ] = 1;
for ( int i = 1; i <= n; i ++ ) {
cin >> a[ i ];
for ( int j = sum; j >= 0; j -- ) {
dp[ j + a[ i ] ] += dp[ j ];
if ( dp[ j + a[ i ] ] >= mod )
dp[ j + a[ i ] ] -= mod;
}
sum += a[ i ];
}
if ( sum % 2 || !dp[ sum / 2 ] ) {
cout << 0;
return 0;
}
for ( int i = 1; i <= n; i ++ ) {
for ( int j = 0; j <= sum; j ++ )
mp[ j ] = dp[ j ];
for ( int j = 0; j <= sum; j ++ ) {
if ( a[ i ] + j > sum )
break;
mp[ j + a[ i ] ] += mod - mp[ j ];
if ( mp[ j + a[ i ] ] >= mod )
mp[ j + a[ i ] ] -= mod;
}
num = sum - a[ i ];
for ( int j = 1; j <= num; j ++ ) {
if ( ( num + j ) % 2 )
continue;
if ( mp[ ( num + j ) / 2 - j ] )
mpp[ j ] ++;
}
}
for ( int i = 1; i <= sum; i ++ ) {
if ( mpp[ i ] == n )
v.push_back( i );
}
cout << v.size() << "\n";
for ( auto i : v )
cout << i << " ";
}
/*
6
3 6 4 5 1 2
*/
Compilation message (stderr)
bootfall.cpp:50:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
50 | main () {
| ^~~~
# | 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... |