제출 #700849

#제출 시각아이디문제언어결과실행 시간메모리
700849tamthegodBootfall (IZhO17_bootfall)C++17
100 / 100
354 ms5692 KiB
// Make the best become better
// No room for laziness
#include<bits/stdc++.h>

#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 500 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, a[maxN];
int f[maxN * maxN];
int cnt[maxN * maxN];
void ReadInput()
{
    cin >> n;
    for(int i=1; i<=n; i++)
        cin >> a[i];
}
void Solve()
{
    int sum = 0;
    bool ok1 = false, ok2 = false;
    for(int i=1; i<=n; i++)
    {
        sum += a[i];
        if(a[i] & 1) ok1 = true;
        else ok2 = true;
    }
    if(ok1 & ok2)
    {
        cout << 0;
        return;
    }
    int tmp = sum;
    f[0] = 1;
    for(int i=1; i<=n; i++)
        for(int s=tmp; s>=a[i]; s--)
            f[s] += f[s - a[i]];
    if(!f[sum / 2])
    {
        cout << 0;
        return;
    }
    for(int i=1; i<=n; i++)
    {
        int cur = sum - a[i];
        for(int s=a[i]; s<=tmp; s++)
            f[s] -= f[s - a[i]];
        for(int s=0; s<=tmp; s++)
            if(f[s] && s * 2 > cur) cnt[s * 2 - cur]++;
        for(int s=tmp; s>=a[i]; s--)
            f[s] += f[s - a[i]];
    }
    vector<int> res;
    for(int s=1; s<=tmp; s++)
        if(cnt[s] == n) res.pb(s);
    cout << res.size() << '\n';
    for(int v : res)
        cout << v << " ";
}
int32_t main()
{
   // freopen("sol.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...