Submission #501605

#TimeUsernameProblemLanguageResultExecution timeMemory
501605shmadBootfall (IZhO17_bootfall)C++17
6 / 100
1089 ms8260 KiB
#include <bits/stdc++.h> #define int long long #define vt vector #define pb push_back #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define ff first #define ss second #define dbg(x) cerr << #x << " = " << x << '\n' using namespace std; using ll = long long; using pii = pair<int, int>; using vvi = vt< vt<int> >; const int N = 1e6 + 5, mod = 1e9 + 7, inf = 1e18 + 7, B = 500, LIM = (1ll << 60); const double eps = 1e-6; template<class Iterator> std::ostream& print_range(std::ostream& os, Iterator begin, Iterator end) { os << "{"; for (auto it = begin; it != end; os << *it++) if (it != begin) os << ", "; return os << "}"; } template<class X> std::ostream& operator<<(std::ostream& os, const std::vector<X>& vec) { return print_range(os, all(vec)); } int dp[N]; void solve () { int n; cin >> n; vt<int> a(n + 1); int sum = 0; for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i]; if (n & 1) cout << "0\n", exit(0); set<int> ans; vt<int> used(N, 0); dp[0] = 1; for (int val = 1; val <= 2500; val++) { for (int i = 1; i <= n; i++) { int x = a[i], s = sum - a[i]; a[i] = val; s += a[i]; if (s & 1) { a[i] = x; continue; } for (int j = 1; j <= n; j++) { for (int w = s - a[j]; w >= 0; w--) { if (dp[w] == 1) dp[w + a[j]] = 1; } } if (dp[s / 2] == 1) { used[val]++; if (used[val] >= n) ans.insert(val); } a[i] = x; for (int j = 1; j <= s; j++) dp[j] = 0; } } cout << sz(ans) << '\n'; for (auto x: ans) cout << x << ' '; cout << '\n'; } bool testcases = 0; signed main() { cin.tie(0) -> sync_with_stdio(0); int test = 1; if (testcases) cin >> test; for (int cs = 1; cs <= test; cs++) { solve(); } }
#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...