제출 #729674

#제출 시각아이디문제언어결과실행 시간메모리
729674yhlasBootfall (IZhO17_bootfall)C++17
13 / 100
1083 ms472 KiB
#include "bits/stdc++.h" using namespace std; int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector <int> a(n + 1, 0); int sm = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; sm += a[i]; } if (sm % 2) return cout << 0, 0; int m = (sm + 5000)>>1; vector <int> dp(m + 1, 0); dp[0] = 1; for (int i = 1; i <= n; i++) { for (int j = m - a[i]; j >= 0; j--) dp[j + a[i]] += dp[j]; } if (!dp[sm>>1]) return cout << 0, 0; vector <int> ans; int x = 0; while (++x <= 5000) { int smv = sm + x; int mv = smv>>1; vector <int> v = a; v.push_back(x); vector <int> can = dp; for (int i = mv; i >= x; i--) can[i] += can[i - x]; bool tr = true; for (int i = 1; i <= n + 1; i++) { int x = smv - v[i]; if (x % 2) { tr = false; break; } x >>= 1; for (int j = v[i]; j <= x; j++) can[j] -= can[j - v[i]]; if (!can[x]) { tr = false; break; } for (int j = x; j >= v[i]; j--) can[j] += can[j - v[i]]; } if (tr) ans.push_back(x); } cout << (int)ans.size() << '\n'; for (auto i : ans) cout << i << ' '; }
#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...