Submission #677768

#TimeUsernameProblemLanguageResultExecution timeMemory
677768MherBootfall (IZhO17_bootfall)C++14
13 / 100
1087 ms5308 KiB
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <cmath> #include <iostream> #include <map> #include <set> #include <string> #include <vector> #include <queue> using namespace std; const int N = 503, mod = 1e9 + 7; int n, sum = 0; int a[N]; set<int> dp[N]; void solve() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; } if (sum % 2 == 1) { cout << 0 << endl; return; } dp[0].insert(0); for (int i = 1; i <= n; i++) { set<int> nw; for (auto s : dp[0]) { nw.insert(s + a[i]); } dp[0].insert(nw.begin(), nw.end()); } if (dp[0].count(sum / 2) == 0) { cout << 0 << endl; return; } for (int k = 1; k <= n; k++) { dp[k].insert(0); for (int i = 1; i <= n; i++) { if (i == k) continue; set<int> nw; for (auto s : dp[k]) { nw.insert(s + a[i]); } dp[k].insert(nw.begin(), nw.end()); } int ns = sum - a[k]; set<int> nt; for (auto s : dp[k]) { int kx = ns - 2 * s; if (kx >= 0) { nt.insert(kx); } } dp[k] = nt; } set<int> ans = dp[1]; for (int i = 2; i <= n; i++) { set<int> el; for (auto s : ans) { if (dp[i].count(s) == 0) el.insert(s); } for (auto s : el) ans.erase(s); } cout << ans.size() << endl; for (auto s : ans) { cout << s << ' '; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while (t--) solve(); 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...