제출 #169781

#제출 시각아이디문제언어결과실행 시간메모리
169781super_j6Bootfall (IZhO17_bootfall)C++14
65 / 100
516 ms38016 KiB
#include <iostream> #include <cstdio> #include <algorithm> #include <set> using namespace std; #define endl '\n' #define pi pair<int, int> const int maxn = 500, m = 250001; int n; int a[maxn], dp[m]; set<int> cur; int s; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin >> n; dp[0] = 1; for(int i = 0; i < n; i++){ cin >> a[i]; s += a[i]; for(int j = s - a[i]; j >= 0; j--){ dp[j + a[i]] += dp[j]; } } if(s % 2 || !dp[s / 2]){ cout << 0 << endl; cout << endl; return 0; } for(int i = 1; i < 3 * m / 2; i++) cur.insert(i); for(int i = 0; i < n; i++){ for(int j = 0; j <= s - a[i]; j++){ dp[j + a[i]] -= dp[j]; } for(auto it = cur.begin(); it != cur.end();){ int x = *it; it++; if((s - a[i] + x) % 2 || !dp[(s - a[i] + x) / 2]) cur.erase(x); } for(int j = s - a[i]; j >= 0; j--){ dp[j + a[i]] += dp[j]; } } cout << cur.size() << endl; for(auto it = cur.begin(); it != cur.end();){ int j = *it; it++; cout << j; if(it != cur.end()) cout << " "; } cout << endl; return 0; }
#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...