Submission #1351012

#TimeUsernameProblemLanguageResultExecution timeMemory
1351012dex111222333444555Bootfall (IZhO17_bootfall)C++20
100 / 100
622 ms3104 KiB
#include <bits/stdc++.h>
#define all(v) begin(v), end(v)
#define dbg(x) "[" #x " = " << x << "]"
#define ii pair<int, long long>
#define fi first
#define se second
#define siz(v) (int)(v).size()
#define lli pair<long long, int>
#define BIT(x, i) (((x) >> (i)) & 1)

using namespace std;

const int infINT = 1e9 + 1323;
const long long mod = 1e18 + 7, inf = 1e18 + 123123;

template<class X, class Y> bool minimize(X &x, const Y &y){return x > y ? x = y, 1: 0;}
template<class X, class Y> bool maximize(X &x, const Y &y){return x < y ? x = y, 1: 0;}

void add(long long &a, const long long &b){
    a += b;
    if (a >= mod) a -= mod;
}

void sub(long long &a, const long long &b){
    a -= b;
    if (a < 0) a += mod;
}

long long mul(const long long &a, const long long &b){
    return 1LL * a * 1LL * b % mod;
}

const int MAXN = 505;

int numVal, val[MAXN], sum;
long long f[MAXN * MAXN];
bool res[MAXN * MAXN];

void input(){
    cin >> numVal;
    for(int i = 1; i <= numVal; i++) cin >> val[i], sum += val[i];
}

void solve(){
    f[0] = 1;
    for(int i = 1; i <= numVal; i++){
        for(int j = sum - val[i]; j >= 0; j--){
            add(f[j + val[i]], f[j]);
        }
    }

    for(int i = 0; i <= sum; i++) res[i] = ((sum % 2 == 0) && (f[sum / 2]));

    for(int i = 1; i <= numVal; i++){
        for(int j = 0; j <= sum - val[i]; j++){
            sub(f[j + val[i]], f[j]);
        }

        for(int j = 1; j <= sum; j++){
            int nsum = sum + j - val[i];
            res[j] &= ((nsum % 2 == 0) && ((f[nsum / 2]) || ((nsum / 2 >= j) && f[nsum / 2 - j])));
        }

        for(int j = sum - val[i]; j >= 0; j--){
            add(f[j + val[i]], f[j]);
        }
    }

    int cnt = 0;
    for(int j = 1; j <= sum; j++) cnt += res[j];

    cout << cnt << '\n';
    for(int j = 1; j <= sum; j++) if (res[j]) cout << j << ' '; cout << '\n';
}

bool M1;

bool M2;
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define task "BOOTFALL"
    if (fopen(task".in", "r")){
        freopen(task".in", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    input();
    solve();
    cerr << (&M2 - &M1) / 1048576 << " mb\n";
    cerr << (1.0 * clock()) / CLOCKS_PER_SEC << ".s\n";
}

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(task".in", "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(task".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...