/*
...:... ..::::::----:::::::. . .. ::: -- . *#%@%%@@@%%#%#***++=+=====+++=+
......:*:#* .::::-::::--:-:::. .+%@@@@@@@@@@@@@@@@@@@@@@@@@#. .-++#%@@@@@@@@%#@%##***+++:
...... .+@@@@@@::::::::--:::. %@@@@@@@@@@@@@@@@@@@@@@@@@@@@@* :-::--=*#%#@@%%%@@%
....... :::::::::::. +@@@@@@@@@@@@@@@@@@@@@@@@%@%@@@@@@@@@@#- .:...:... ..:-:=+
.......:...:..:.....::::::::*%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@% :-----------:::::.:
.....:.:..::::::::::. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%%@@@@@@@@@@@@. ::----------------
#=: ...:: -@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%%@@@@@@@@*:=..:---:----::------
**#%%@@@@@@@@%: *@@@@%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%@@@@@@@@=: .:--------------
====----=-::*@@@@@@@@@#+ @@@@@@@@@@@@@@@@@@@%#%@@@@@@@@@@@@@@@@@@@@@@@@%%@##--:::::::-:-----=
--=-===-----. =@@@@@@#+*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*.:::-::::::::::::
-------===----: .@@@@%#@@@@@@@@@@@%+---=*#**##%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@-::-------::-:::
=-------:-----::: *@@@@@@@@@@- ..:.::::.::=-+++###%##%@@@@@@@@@@@@@@@#. :::----:::---::
+*+=---------=----: @@@@@@@: ::====-:::.:::-::-:--:-:.::=+#@@@@@@@@@@@@@@-:-======--------
:=*+=-----------:. %@@@@@@*----==+=++=----=-=----:---:----:::-+%@@@@@@@@@@ ..:--===+=+
. -++=---------=:.*@@@@@@#+-==+++=+=+==========----===-------::=*@@@@@@@@# ..
.... =++=------:. #@@@@@%---=+==========+======-++======-=-======+#@@@@#@@ ..:::::::::..
....... .=+==--:: %@@@@@+:-=+===----:=---=+=====--+=+**++++*+==-=--=%@@@@% ....:::::..:-=+
::::...:.. :+==-: :@@@@@#-===-: .::::-----------=====+=++*+++++=-.=@@@% .:...........:*
...:....::.. -+= *@@@@@:---::=*@@@+: .:------------====+=+=++==-:.:%@@@. .:::....:....
::....:..:..:... @@@@@: :-=#@@@@@@@@@@@*: .:--:---=-==---==========--:@@@# :::::.: .......
...:.....:....... -@@@* :-==+*- :+@@@@@@@#+======--:. ..-===-:@@@- ...::::::......
.:....:......... @@@@-.--+=:. : =%@@@%**+**+**@@@@@@%%#*=.:==-=@@# .......
....:.....::.:.. =%%@@@% :-=+#%@@@@@@@@@@@#++#@#*+**#%@@@@@@@@@@@@@@+==-#@@: :---::..
.:.:::::.. .. .. =@+-@@- ---++*%@@#:%@@@@@@@@%*-::--=#%*-. :=*%@@+-:#@* ...::---===----:
.......... #-#@::--:.....:===. .-**+***=:..-*@@@@@@- : --:::@@#*#+-. ....:
:..... ... ...::*#+=#@@:-=--:---=+*##@@@%*=--:=-..:=*@@#==@@@@@@+@*+-. .@@.:*#@@@@@@@@@#*-:.
=#%-:-=:---:-:.:.:::. .-==-:::--==+++--#%=+@@@@%+=.=@@+##*+=-. .::=*%@@@@
+*+-------:----:.......:-===-::-=--=-=++*++**=.:-++: #@ :=*#%%@%%*=-.
:+*===--:-:-:::::::::.-*%#==--:==----:---=+===-.:--. %@+ . :=*
+=:. %**%*--==---==:=--=+#@@+. .-=+#%+-:::::.::----: .@@. ....:......
+*%%@@@@%#*-. -+==-=-====---=+#@@@#=..::.:::: :*@--::::--::--: @%- ....... ...........
.::-..:-:-=+#%#%%%%+:-=--=====++#%@@*-.:+@@@@%#%#*#= :@#*+=-=-:-:-=- -@. .:..................
.::. :. .... *%+@@%-++++++##%#=---===++*%@@@@@@@@@#****++===-==. @@. ...:::....... .
.: .. . +:=--:==+++*#*++++===--::-=*#@@@%%*====+****++++=:.+%: ......::::::.......
:: . . .. :=-+=:.=+=+++--=*#+- -.. .:--===+++*++++=:*@- . .::::::
.- . .-:=.. -+======*#**@@@@@@@@@@@##*+- .=+++++##***==@+ -@%-. ...
-: . .. .-=- :. .*+==+===: .:=+#@@@@@@@@@@@*##%*****#*+%%:=#%%%#*+-.
.::+.-- -****+**+=-==-:----. .:-=@@@@#*+++++*= ...:+++####%@%%##*=-::
*-:= -- = -+**++*+==+===++++*#*+===*+=:. .-+==++*++= .. :.. ...:-:--::+**+
:-+*%%@@%*=. -*@#++***++===+++=+*%@@@@@@@@%#*=----++=**+=== . ... ... :..-.:-:. -:
-**##%%#*+++#**#**-: .-=+##**=---=====--:-==+*#**++*+*+*####-:*: ..: -:...:... . .---..
#+=====+##*=-===---+#%+==++*%@#+::::---:::::-=-=+*****+=*%@#=-=+ .: :.. ...:... :-.=. :
==-:. ===+#@@@@@@@@*:==+++*#@@*-----:::---::.::--====*%#: :=*= . .+=. :. :.::. .*%=+: :
:... .+@@@@@@@@@@@@+ .-==++++*+#%%#=:--++----==-:-----=**+*##++ .-:. :.:: : =- #%:.-
-=-:.@@@@@@@@@%@@@* :-====+++*++*#%@@@@%%%%####*###**%@#: :+ . :-:=:...**#@+.:-
:::.=@@@@%%@@@@@@@.:--+=+=+++++++*###@@@@@@@@@@@@%*####+=#@@#. -%*- .. -. . .=.*@: .
--:-@@@@@%@@@@@@@# :====+++===++*++*#%%%%@@%#*==-++***+-:+*=++++--=+*+=--: . :: -:-%= .
---@@@@@@@@@@%%@@@..======++++*+****#*%@@%%%#*++++#**=+-=@@@%%@@@@@@%%#++==%%- =-*+
=+=@@@@@@@%%@@@@@@= :-=+==+++***#*#*###%#%%##+=+*****++-:@@@@@@@@*%+=++==+- @@@+ -. @@@@@
--. @@@@@@@@%@@@@@@::==++=+*++*+++++**##%%#%*+####%*+++- +@@@@@@@%%%%%*+-:-=: @*@@++@@@@@#@@%
##%%####%%%%@@% .::. %%%*#*+:- .:- ..:-+*+=*@@@@@@
*/
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
const int inf = 2e18,N = 5e5+1,MOD = 1e9+7;
bitset<250001> cando[501];
int dp[250001];
void solve() {
int n;
cin >> n;
int s = 0;
bool even = 0,odd = 0;
vi a(n+1);
for (int i=1;i<=n;i++) {
cin >> a[i];
if (a[i]%2) odd = 1;
else even = 1;
s+=a[i];
}
memset(dp,-1,sizeof dp);
dp[0] = 0;
for (int i=1;i<=2*n;i++) {
int v = a[(i > n) ? (i-n) : i];
for (int j = 250000;j>=v;j--) dp[j] = max(dp[j],dp[j-v]);
dp[0] = dp[v] = i;
if (i == n && (s%2 || dp[s/2] == -1)) {
cout << 0 << '\n';
return;
}
if (i >= n) {
for (int j = 0;j<=250000;j++) {
if (i >= n && dp[j] > i-n+1) cando[(i<2*n)?(i-n+1):(1)][j] = 1;
}
}
}
if ((odd && even)) {
cout << 0 << '\n';
return;
}
vi ans;
for (int v = odd;v<=250000;v+=2) {
int fl = 1;
for (int i = 1;i<=n;i++) {
int req = (s+v-a[i])/2-v;
if (req < 0) {
fl = -1;
break;
}
if (!cando[i][req]) {
fl = 0;
break;
}
}
if (fl == 1) ans.push_back(v);
if (fl == -1) break;
}
cout << ans.size() << '\n';
for (auto it : ans) cout << it << ' ';
cout << '\n';
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Dodi
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while (t --> 0) 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |