Submission #36161

#TimeUsernameProblemLanguageResultExecution timeMemory
36161cheater2kBootfall (IZhO17_bootfall)C++14
100 / 100
496 ms5164 KiB
#include <bits/stdc++.h> using namespace std; const int N = 505; const int MAX = N * N; int n, a[N]; int sum; int dp[MAX]; // knapsack int tmp[MAX]; // for solve(pos) int check[MAX]; void solve(int pos) { for (int i = 0; i <= sum; ++i) tmp[i] = dp[i]; for (int i = 0; i <= sum; ++i) { // we do not use a[pos] if (i >= a[pos]) { tmp[i] -= tmp[i - a[pos]]; } } for (int i = 0; i <= sum; ++i) { if (tmp[i] != 0 && a[pos] + 2 * i - sum >= 0) check[a[pos] + 2 * i - sum]++; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; // prepare KNAPSACK dp[0] = 1; for (int i = 1; i <= n; ++i) { sum += a[i]; for (int j = sum; j >= a[i]; --j) { dp[j] += dp[j - a[i]]; } } if ((sum & 1) || (dp[sum / 2] == 0)) return printf("0\n"), 0; // invalid for (int i = 1; i <= n; ++i) solve(i); int cnt = 0; for (int i = 1; i <= sum; ++i) if (check[i] == n) ++cnt; printf("%d\n", cnt); for (int i = 1; i <= sum; ++i) if (check[i] == n) printf("%d ", i); printf("\n"); }
#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...