Submission #1182111

#TimeUsernameProblemLanguageResultExecution timeMemory
1182111InvMODBootfall (IZhO17_bootfall)C++17
100 / 100
143 ms3504 KiB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define gcd __gcd
#define sz(v) (int) v.size()
#define pb push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define compact(v) (v).erase(unique(all(v)), (v).end())
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define ROF(i, a, b) for(int i = (a); i >= (b); i--)
#define dbg(x) "[" #x " = " << (x) << "]"
///#define int long long

using ll = long long;
using ld = long double;
using ull = unsigned long long;

template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;}

const int N = 2e5+5;
const ll MOD = 1e9+7;
const ll INF = 1e18;




void solve()
{
    int n; cin >> n;

    vector<int> a(n + 1);
    FOR(i, 1, n) cin >> a[i];

    int sum = accumulate(1 + all(a), 0);
    if(sum & 1) return cout << "0\n", void();

    vector<ll> dp((sum / 2) + 1, 0);
    dp[0] = 1;
    FOR(i, 1, n){
        ROF(j, sum / 2, a[i]){
            dp[j] += dp[j - a[i]];
        }
    }

    if(!dp[sum / 2]) return cout << "0\n", void();

    vector<int> cnt(sum + 1, 0);
    FOR(i, 1, n){
        FOR(j, a[i], sum / 2){
            dp[j] -= dp[j - a[i]];
        }

        FOR(j, 0, sum - a[i]){
            if(sum - a[i] - (2 * j) <= 0) break;
            if(dp[j]){
                cnt[sum - a[i] - (2 * j)]++;
            }
        }

        ROF(j, sum / 2, a[i]){
            dp[j] += dp[j - a[i]];
        }
    }

    vector<int> ans;
    FOR(i, 1, sum) if(cnt[i] == n) ans.pb(i);

    cout << sz(ans) << "\n"; for(int v : ans) cout << v <<" "; cout << "\n";
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    #define name "InvMOD"
    if(fopen(name".INP", "r")){
        freopen(name".INP","r",stdin);
        freopen(name".OUT","w",stdout);
    }

    int t = 1; //cin >> t;
    while(t--) solve();
    return 0;
}

Compilation message (stderr)

bootfall.cpp: In function 'int main()':
bootfall.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen(name".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |         freopen(name".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...