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;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 505;
int a[N];
int main(){
int n;
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%d", a+i);
// I will solve for fixed Tima's strength, it can be up to O(n^2)
int sm = accumulate(a+1, a+n+1, 0);
vector<int> A;
for(int x = 0; x <= sm; ++x){
// x => Tima's fixed strength
// Tima's strength is given, we just need to say whether game is friendly or not.
// To say that, we need to know every round is draw or not.
a[n+1] = x;
bool done = 1;
// wr;
for(int ad = 1; ad <= n+1 and done; ++ad){
// ad's person is recorder in this round
// He will not play in this round.
vector<int> v;
for(int i = 1; i <= n+1; ++i)
if(i != ad)
v.pb(a[i]);
// for(int i : v)
// printf("%d ", i);
// puts("");
int wow = accumulate(all(v), 0);
vector<bool> dp(wow+1, false);
dp[0] = 1;
for(int &to : v)
for(int i = wow; i >= to; --i)
if(dp[i-to])
dp[i] = 1;
done &= (wow%2 == 0 and dp[wow/2]);
}
if(done)
A.pb(x);
}
// wr;
printf("%d\n", (int)A.size());
for(int i : A)
printf("%d ", i);
puts("");
return 0;
}
Compilation message (stderr)
bootfall.cpp: In function 'int main()':
bootfall.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
bootfall.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf("%d", a+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... |