제출 #1126704

#제출 시각아이디문제언어결과실행 시간메모리
1126704LilPlutonBootfall (IZhO17_bootfall)C++20
13 / 100
1095 ms444 KiB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define vpi vector<pair<int, int>>
#define pii pair<int, int>
#define all(c) (c).begin(), (c).end()
#define endll '\n'
#define fastio ios::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
mt19937 rng(time(0));

int x[] = {1, -1, 0, 0}; 
int y[] = {0, 0, 1, -1};


void solve() {
    int n;
    cin >> n;
    deque<int>v;
    int s = 0;
    for(int i = 0; i < n; ++i){
        int x;
        cin >> x;
        s += x;
        v.push_back(x);
    }
    vector<int>ans;
    for(int ne = 1; ne <= 1000; ++ne){
        v.push_back(ne);
        s += ne;
        int cnt = 0;
        for(int i = 0; i < n + 1; ++i){
            s -= v[i];
            if(s & 1){
                s += v[i];
                continue;
            }
            vector<bool>dp(s + 1, 0);
            dp[0] = 1;
            for(int j = 0; j < n + 1; ++j){
                if(i == j){
                    continue;
                }
                for(int l = s; l >= v[j]; --l){
                    if(dp[l - v[j]] == true){
                        dp[l] = true;
                    }
                }
            }
            if(dp[s / 2]){
                cnt++;
            }
            s += v[i];
        }
        if(cnt == n + 1){
            ans.pb(ne);
        }
        s -= ne;
        v.pop_back();
    }
    cout << ans.size() << endl;
    for(auto i : ans){
        cout << i << ' ';
    }
}

signed main() {
    fastio
    int T = 1;
    while (T--) {
        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...