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;
using ll = long long;
using ld = long double;
using db = double;
using str = string; // yay python!
using ii = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vii = vector<ii>;
using vpl = vector<pl>;
using vpd = vector<pd>;
#define tcT template<class T
#define tcTU tcT, class U
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
tcT> using PR = pair<T,T>;
// pairs
#define mp make_pair
#define f first
#define s second
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define len(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back
#define pf push_front
const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18; // not too close to LLONG_MAX
const ld PI = acos((ld)-1);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!!
vi vals;
bool is_solvable(){
int sm = 0;
trav(i, vals) sm += i;
//cout << sm << endl;
if(sm%2) return 0;
sm/=2;
bool dp[vals.size()+1][sm+1]; // PLAYER, SUM
FOR(i, 0, vals.size()+1) dp[i][0] = true;
FOR(i,1, sm+1) dp[0][i] = 0;
FOR(player, 1, vals.size()+1){
FOR(score,1, sm+1){
dp[player][score] = dp[player-1][score];
if(score-vals[player-1]>=0)
dp[player][score] = (dp[player][score] || dp[player-1][score-vals[player-1]]);
//cout << player << " " << score << " " << dp[player][score] << endl;
}
}
return dp[vals.size()][sm];
}
int main(){
int N;
cin >> N;
vals.resize(N);
vi nums(N);
//vi st;
F0R(i, nums.size()) cin >> nums[i];
vi myNums;
FOR(i, 1, 700) myNums.pb(i);
F0R(i, N) vals[i] = nums[i];
if (!is_solvable()){
cout << 0;
return 0;
}
F0R(round, N){
vi myNewNums;
F0R(i, N) vals[i] = nums[i];
trav(num, myNums){
vals[round] = num;
if(is_solvable()){
myNewNums.pb(num);
}
}
myNums = myNewNums;
}
cout << myNums.size() << endl;
trav(i, myNums) cout << i << " ";
cout <<endl;
}
Compilation message (stderr)
bootfall.cpp: In function 'bool is_solvable()':
bootfall.cpp:37:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
| ^
bootfall.cpp:74:5: note: in expansion of macro 'FOR'
74 | FOR(i, 0, vals.size()+1) dp[i][0] = true;
| ^~~
bootfall.cpp:37:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
| ^
bootfall.cpp:77:5: note: in expansion of macro 'FOR'
77 | FOR(player, 1, vals.size()+1){
| ^~~
bootfall.cpp: In function 'int main()':
bootfall.cpp:37:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
| ^
bootfall.cpp:38:18: note: in expansion of macro 'FOR'
38 | #define F0R(i,a) FOR(i,0,a)
| ^~~
bootfall.cpp:94:5: note: in expansion of macro 'F0R'
94 | F0R(i, nums.size()) cin >> nums[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... |