# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
514689 | 2022-01-18T11:00:08 Z | Mazaalai | Bootfall (IZhO17_bootfall) | C++17 | 21 ms | 3000 KB |
#include <bits/stdc++.h> #define pb push_back #define LINE "-------------------\n" #define sz(x) int(x.size()) using namespace std; using ll = long long; const int N = 500+1; const int M = 500*500+1; vector <int> ans; int n, m, nums[N]; const ll MOD = 1e9+7; ll dp[M], dp1[M], sum; signed main() { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); cin >> n; for (int i = 1; i <= n; i++) cin >> nums[i]; dp[0] = 1; for (int i = 1; i <= n; i++) { int& x = nums[i]; sum += x; for (int j = M-1; j >= x; j--) dp[j] = (dp[j] + dp[j-x]) % MOD; } // for (int i = 1; i <= 10; i++) cout << dp[i] << " \n"[i==10]; if (sum & 1 || dp[sum / 2] == 0) { cout << "0\n"; return 0; } for (int i = 1; i <= n; i++) { int& x = nums[i]; for (int j = x; j <= M-1; j++) dp[j] = (dp[j] - dp[j-x] + MOD) % MOD; /* left = (sum - x + a) / 2 == j; sum-x+a = 2j a = 2j+x-sum; */ // cout << LINE;B // cout << x << ":\n"; // cout << "dp: "; // for (int i = 1; i <= 10; i++) cout << dp[i] << " \n"[i==10]; for (int j = M-1; j >= 0; j--) { int a = 2 * j + x - sum; if (dp[j] > 0 && a >= 0) { // cout << j << " " << a << '\n'; dp1[a]++; // cout << 2 * j + x - sum << ' '; } } // cout << "\n"; for (int j = M-1; j >= x; j--) dp[j] = (dp[j] + dp[j-x]) % MOD; // cout << "dp: "; // for (int i = 1; i <= 10; i++) cout << dp[i] << " \n"[i==10]; } for (int j = 0; j < M; j++) { if (dp1[j] == n) ans.pb(j); } cout << sz(ans) << '\n'; for (auto&el:ans) cout << el << ' '; cout << '\n'; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 3000 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 3000 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 3000 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 3000 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 3000 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 3000 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |