Submission #312316

#TimeUsernameProblemLanguageResultExecution timeMemory
312316ttnhuy313Bootfall (IZhO17_bootfall)C++14
0 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; const int N = 505; int dp[N * N], cnt[N], a[N], n, tmp[N * N]; int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; int s = 0; for (int i = 1; i <= n; ++i) { cin >> a[i]; s += a[i]; } dp[0] = 1; for (int i = 1; i <= n; ++i) { for (int j = s; j >= 0; --j) if (a[i] <= j) dp[j] += dp[j - a[i]]; } if (dp[s / 2] == 0) { cout << 0 << endl; return 0; } for (int i = 1; i <= n; ++i) { for (int j = 0; j <= s; ++j) tmp[j] = dp[j]; tmp[a[i]]--; for (int j = a[i] + 1; j <= s; ++j) tmp[j] -= tmp[j - a[i]]; s -= a[i]; for (int j = 0; j <= s / 2; ++j) if (tmp[j] > 0) { cnt[s - 2 * j]++; } s += a[i]; } vector <int> res; res.clear(); for (int i = 1; i <= s; ++i) if (cnt[i] == n) res.push_back(i); cout << res.size() << endl; for (int v : res) cout << v << ' '; 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...