Submission #1357867

#TimeUsernameProblemLanguageResultExecution timeMemory
1357867nathlol2Bootfall (IZhO17_bootfall)C++20
100 / 100
297 ms5824 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 505, MD = 676767676767;
int n, sm, a[N], ok[N * N], dp[N * N], dp1[N * N];

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for(int i = 1;i<=n;i++) cin >> a[i], sm += a[i];
    dp[0] = 1;
    for(int i = 1;i<=n;i++) for(int j = sm;j>=a[i];j--) dp[j] = (dp[j] + dp[j - a[i]]) % MD;
    if(sm % 2 == 1 || dp[sm / 2] == 0) return cout << "0", 0;
    for(int i = 0;i<=sm;i++) ok[i] = 1;
    for(int i = 1;i<=n;i++){
        for(int j = a[i];j<=sm;j++) dp[j] = (dp[j] - dp[j - a[i]] + MD) % MD;
        for(int j = sm - a[i];j>=(sm - a[i]) / 2;j--) if(dp[j] == 0) ok[2 * j - sm + a[i]] = 0;
        for(int j = sm - a[i] + 1;j<=sm;j++) ok[j] = 0;
        for(int j = (sm - a[i]) % 2 + 1;j<=sm;j+=2) ok[j] = 0;
        for(int j = sm;j>=a[i];j--) dp[j] = (dp[j] + dp[j - a[i]]) % MD;
    }
    vector<int> ans;
    for(int i = 1;i<=sm;i++) if(ok[i]) ans.push_back(i);
    cout << ans.size() << '\n';
    for(auto x : ans) cout << x << ' ';
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...