Submission #1301766

#TimeUsernameProblemLanguageResultExecution timeMemory
1301766apxoBootfall (IZhO17_bootfall)C++20
44 / 100
1064 ms7128 KiB
#include "bits/stdc++.h" using namespace std; #ifdef duc_debug #include "bits/debug.h" #else #define debug(...) #endif const int maxn = 505; const int N = 500 * 500 + 5; const int mod[] = {998244353, 1000000009, 1000000007}; int n, a[maxn]; int f[N][3], g[N][3]; int cnt[N]; void solve() { cin >> n; int sum = 0; f[0][0] = f[0][1] = f[0][2] = 1; for (int i = 1; i <= n; ++i) { cin >> a[i]; for (int j = N - 1; j >= a[i]; --j) { for (int md = 0; md < 3; ++md) { f[j][md] += f[j - a[i]][md]; if (f[j][md] >= mod[md]) { f[j][md] -= mod[md]; } } } sum += a[i]; } if (sum & 1 || (!f[sum / 2][0] and !f[sum / 2][1] and !f[sum / 2][2])) { cout << 0; return; } for (int i = 1; i <= n; ++i) { for (int j = 0; j < N; ++j) { for (int md = 0; md < 3; ++md) { g[j][md] = f[j][md]; } } for (int j = a[i]; j < N; ++j) { for (int md = 0; md < 3; ++md) { g[j][md] -= g[j - a[i]][md]; if (g[j][md] < 0) g[j][md] += mod[md]; if (g[j][md] >= mod[md]) g[j][md] -= mod[md]; } } for (int j = (sum - a[i]) / 2; j >= 0; --j) { bool ok = 0; for (int md = 0; md < 3; ++md) { if (g[j][md]) { ok = 1; break; } } if (ok) { // debug(i, sum - a[i] - j * 2); ++cnt[(sum - a[i]) - j * 2]; } } } vector<int> res; for (int i = 1; i < N; ++i) { if (cnt[i] == n) res.push_back(i); } cout << (int)res.size() << '\n'; for (auto i : res) cout << i << " "; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); 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...