Submission #1047470

# Submission time Handle Problem Language Result Execution time Memory
1047470 2024-08-07T13:25:37 Z adrielcp Bootfall (IZhO17_bootfall) C++17
100 / 100
275 ms 6092 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lld double
#define int ll
#define usaco(fname) freopen(#fname ".in","r",stdin);freopen(#fname ".out","w",stdout);
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
// const ll INF = 1e18;
const int INF = 1e9;
const int mod = 1e9+7;
const lld PI = acos(-1.0);
int di[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dj[] = {0, 0, 1, -1, 1, -1, 1, -1};
#define debug(x) cout << #x << ": " << x << endl;
#define add(a, b) a += b, a %= mod
#define mul(a, b) ((a % mod) * (b % mod)) % mod
#define all(x) x.begin(),x.end()

const int N = 25e4 + 69;
void solve() {
  int n;cin>>n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int sm = accumulate(all(a),0ll);

  vector<int> dp(N);
  dp[0] = 1;
  for (int i = 0; i < n; i++) for (int j = sm; j >= a[i]; j--) dp[j] += dp[j-a[i]];

  if (sm % 2 != 0 || !dp[sm/2]) {
    cout << 0 << endl;
    return;
  }

  vector<int> ans(N);
  for (int i = 0; i < n; i++) {
    for (int j = a[i]; j <= sm; j++) dp[j] -= dp[j-a[i]];
    for (int j = 1; j <= sm; j++) {
      int nowsum = sm + j - a[i];
      if (nowsum % 2 == 0 && dp[nowsum/2]) ans[j]++;
    }
    for (int j = sm; j >= a[i]; j--) dp[j] += dp[j-a[i]];
  }

  vector<int> res;
  for (int i = 1; i < N; i++) if (ans[i] == n) res.push_back(i);

  cout << res.size() << endl;
  for (auto el : res) cout << el << " ";

  // set<int> st;
  // for (int i = 0; i < N; i++) if (vis[i]) st.insert(i);

  // cout << st << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(0);cin.tie(0);
  int t=1;
  while(t--) solve();

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 4392 KB Output is correct
5 Correct 1 ms 4188 KB Output is correct
6 Correct 1 ms 4188 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Correct 1 ms 4188 KB Output is correct
9 Correct 1 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 4392 KB Output is correct
5 Correct 1 ms 4188 KB Output is correct
6 Correct 1 ms 4188 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Correct 1 ms 4188 KB Output is correct
9 Correct 1 ms 4188 KB Output is correct
10 Correct 1 ms 4184 KB Output is correct
11 Correct 1 ms 4188 KB Output is correct
12 Correct 1 ms 4188 KB Output is correct
13 Correct 1 ms 4188 KB Output is correct
14 Correct 1 ms 4188 KB Output is correct
15 Correct 1 ms 4300 KB Output is correct
16 Correct 1 ms 4188 KB Output is correct
17 Correct 2 ms 4188 KB Output is correct
18 Correct 2 ms 4188 KB Output is correct
19 Correct 2 ms 4188 KB Output is correct
20 Correct 1 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 4392 KB Output is correct
5 Correct 1 ms 4188 KB Output is correct
6 Correct 1 ms 4188 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Correct 1 ms 4188 KB Output is correct
9 Correct 1 ms 4188 KB Output is correct
10 Correct 1 ms 4184 KB Output is correct
11 Correct 1 ms 4188 KB Output is correct
12 Correct 1 ms 4188 KB Output is correct
13 Correct 1 ms 4188 KB Output is correct
14 Correct 1 ms 4188 KB Output is correct
15 Correct 1 ms 4300 KB Output is correct
16 Correct 1 ms 4188 KB Output is correct
17 Correct 2 ms 4188 KB Output is correct
18 Correct 2 ms 4188 KB Output is correct
19 Correct 2 ms 4188 KB Output is correct
20 Correct 1 ms 4188 KB Output is correct
21 Correct 2 ms 4188 KB Output is correct
22 Correct 2 ms 4188 KB Output is correct
23 Correct 2 ms 4188 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
25 Correct 4 ms 4444 KB Output is correct
26 Correct 4 ms 4444 KB Output is correct
27 Correct 3 ms 4188 KB Output is correct
28 Correct 4 ms 4188 KB Output is correct
29 Correct 4 ms 4188 KB Output is correct
30 Correct 2 ms 4188 KB Output is correct
31 Correct 3 ms 4444 KB Output is correct
32 Correct 2 ms 4288 KB Output is correct
33 Correct 4 ms 4188 KB Output is correct
34 Correct 4 ms 4188 KB Output is correct
35 Correct 4 ms 4188 KB Output is correct
36 Correct 3 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 4392 KB Output is correct
5 Correct 1 ms 4188 KB Output is correct
6 Correct 1 ms 4188 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Correct 1 ms 4188 KB Output is correct
9 Correct 1 ms 4188 KB Output is correct
10 Correct 1 ms 4184 KB Output is correct
11 Correct 1 ms 4188 KB Output is correct
12 Correct 1 ms 4188 KB Output is correct
13 Correct 1 ms 4188 KB Output is correct
14 Correct 1 ms 4188 KB Output is correct
15 Correct 1 ms 4300 KB Output is correct
16 Correct 1 ms 4188 KB Output is correct
17 Correct 2 ms 4188 KB Output is correct
18 Correct 2 ms 4188 KB Output is correct
19 Correct 2 ms 4188 KB Output is correct
20 Correct 1 ms 4188 KB Output is correct
21 Correct 2 ms 4188 KB Output is correct
22 Correct 2 ms 4188 KB Output is correct
23 Correct 2 ms 4188 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
25 Correct 4 ms 4444 KB Output is correct
26 Correct 4 ms 4444 KB Output is correct
27 Correct 3 ms 4188 KB Output is correct
28 Correct 4 ms 4188 KB Output is correct
29 Correct 4 ms 4188 KB Output is correct
30 Correct 2 ms 4188 KB Output is correct
31 Correct 3 ms 4444 KB Output is correct
32 Correct 2 ms 4288 KB Output is correct
33 Correct 4 ms 4188 KB Output is correct
34 Correct 4 ms 4188 KB Output is correct
35 Correct 4 ms 4188 KB Output is correct
36 Correct 3 ms 4444 KB Output is correct
37 Correct 10 ms 4444 KB Output is correct
38 Correct 14 ms 4444 KB Output is correct
39 Correct 35 ms 4220 KB Output is correct
40 Correct 21 ms 4692 KB Output is correct
41 Correct 44 ms 4188 KB Output is correct
42 Correct 18 ms 4700 KB Output is correct
43 Correct 32 ms 4760 KB Output is correct
44 Correct 34 ms 4828 KB Output is correct
45 Correct 33 ms 4820 KB Output is correct
46 Correct 20 ms 4184 KB Output is correct
47 Correct 20 ms 4644 KB Output is correct
48 Correct 41 ms 4692 KB Output is correct
49 Correct 36 ms 4432 KB Output is correct
50 Correct 20 ms 4632 KB Output is correct
51 Correct 5 ms 2396 KB Output is correct
52 Correct 43 ms 4772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 4392 KB Output is correct
5 Correct 1 ms 4188 KB Output is correct
6 Correct 1 ms 4188 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Correct 1 ms 4188 KB Output is correct
9 Correct 1 ms 4188 KB Output is correct
10 Correct 1 ms 4184 KB Output is correct
11 Correct 1 ms 4188 KB Output is correct
12 Correct 1 ms 4188 KB Output is correct
13 Correct 1 ms 4188 KB Output is correct
14 Correct 1 ms 4188 KB Output is correct
15 Correct 1 ms 4300 KB Output is correct
16 Correct 1 ms 4188 KB Output is correct
17 Correct 2 ms 4188 KB Output is correct
18 Correct 2 ms 4188 KB Output is correct
19 Correct 2 ms 4188 KB Output is correct
20 Correct 1 ms 4188 KB Output is correct
21 Correct 2 ms 4188 KB Output is correct
22 Correct 2 ms 4188 KB Output is correct
23 Correct 2 ms 4188 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
25 Correct 4 ms 4444 KB Output is correct
26 Correct 4 ms 4444 KB Output is correct
27 Correct 3 ms 4188 KB Output is correct
28 Correct 4 ms 4188 KB Output is correct
29 Correct 4 ms 4188 KB Output is correct
30 Correct 2 ms 4188 KB Output is correct
31 Correct 3 ms 4444 KB Output is correct
32 Correct 2 ms 4288 KB Output is correct
33 Correct 4 ms 4188 KB Output is correct
34 Correct 4 ms 4188 KB Output is correct
35 Correct 4 ms 4188 KB Output is correct
36 Correct 3 ms 4444 KB Output is correct
37 Correct 10 ms 4444 KB Output is correct
38 Correct 14 ms 4444 KB Output is correct
39 Correct 35 ms 4220 KB Output is correct
40 Correct 21 ms 4692 KB Output is correct
41 Correct 44 ms 4188 KB Output is correct
42 Correct 18 ms 4700 KB Output is correct
43 Correct 32 ms 4760 KB Output is correct
44 Correct 34 ms 4828 KB Output is correct
45 Correct 33 ms 4820 KB Output is correct
46 Correct 20 ms 4184 KB Output is correct
47 Correct 20 ms 4644 KB Output is correct
48 Correct 41 ms 4692 KB Output is correct
49 Correct 36 ms 4432 KB Output is correct
50 Correct 20 ms 4632 KB Output is correct
51 Correct 5 ms 2396 KB Output is correct
52 Correct 43 ms 4772 KB Output is correct
53 Correct 32 ms 4688 KB Output is correct
54 Correct 45 ms 4820 KB Output is correct
55 Correct 90 ms 5072 KB Output is correct
56 Correct 39 ms 4816 KB Output is correct
57 Correct 94 ms 5068 KB Output is correct
58 Correct 48 ms 4816 KB Output is correct
59 Correct 61 ms 4768 KB Output is correct
60 Correct 12 ms 2396 KB Output is correct
61 Correct 69 ms 5004 KB Output is correct
62 Correct 71 ms 5012 KB Output is correct
63 Correct 75 ms 5072 KB Output is correct
64 Correct 79 ms 5072 KB Output is correct
65 Correct 35 ms 4184 KB Output is correct
66 Correct 43 ms 4388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4440 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 4392 KB Output is correct
5 Correct 1 ms 4188 KB Output is correct
6 Correct 1 ms 4188 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Correct 1 ms 4188 KB Output is correct
9 Correct 1 ms 4188 KB Output is correct
10 Correct 1 ms 4184 KB Output is correct
11 Correct 1 ms 4188 KB Output is correct
12 Correct 1 ms 4188 KB Output is correct
13 Correct 1 ms 4188 KB Output is correct
14 Correct 1 ms 4188 KB Output is correct
15 Correct 1 ms 4300 KB Output is correct
16 Correct 1 ms 4188 KB Output is correct
17 Correct 2 ms 4188 KB Output is correct
18 Correct 2 ms 4188 KB Output is correct
19 Correct 2 ms 4188 KB Output is correct
20 Correct 1 ms 4188 KB Output is correct
21 Correct 2 ms 4188 KB Output is correct
22 Correct 2 ms 4188 KB Output is correct
23 Correct 2 ms 4188 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
25 Correct 4 ms 4444 KB Output is correct
26 Correct 4 ms 4444 KB Output is correct
27 Correct 3 ms 4188 KB Output is correct
28 Correct 4 ms 4188 KB Output is correct
29 Correct 4 ms 4188 KB Output is correct
30 Correct 2 ms 4188 KB Output is correct
31 Correct 3 ms 4444 KB Output is correct
32 Correct 2 ms 4288 KB Output is correct
33 Correct 4 ms 4188 KB Output is correct
34 Correct 4 ms 4188 KB Output is correct
35 Correct 4 ms 4188 KB Output is correct
36 Correct 3 ms 4444 KB Output is correct
37 Correct 10 ms 4444 KB Output is correct
38 Correct 14 ms 4444 KB Output is correct
39 Correct 35 ms 4220 KB Output is correct
40 Correct 21 ms 4692 KB Output is correct
41 Correct 44 ms 4188 KB Output is correct
42 Correct 18 ms 4700 KB Output is correct
43 Correct 32 ms 4760 KB Output is correct
44 Correct 34 ms 4828 KB Output is correct
45 Correct 33 ms 4820 KB Output is correct
46 Correct 20 ms 4184 KB Output is correct
47 Correct 20 ms 4644 KB Output is correct
48 Correct 41 ms 4692 KB Output is correct
49 Correct 36 ms 4432 KB Output is correct
50 Correct 20 ms 4632 KB Output is correct
51 Correct 5 ms 2396 KB Output is correct
52 Correct 43 ms 4772 KB Output is correct
53 Correct 32 ms 4688 KB Output is correct
54 Correct 45 ms 4820 KB Output is correct
55 Correct 90 ms 5072 KB Output is correct
56 Correct 39 ms 4816 KB Output is correct
57 Correct 94 ms 5068 KB Output is correct
58 Correct 48 ms 4816 KB Output is correct
59 Correct 61 ms 4768 KB Output is correct
60 Correct 12 ms 2396 KB Output is correct
61 Correct 69 ms 5004 KB Output is correct
62 Correct 71 ms 5012 KB Output is correct
63 Correct 75 ms 5072 KB Output is correct
64 Correct 79 ms 5072 KB Output is correct
65 Correct 35 ms 4184 KB Output is correct
66 Correct 43 ms 4388 KB Output is correct
67 Correct 73 ms 4820 KB Output is correct
68 Correct 41 ms 2396 KB Output is correct
69 Correct 237 ms 5864 KB Output is correct
70 Correct 148 ms 5332 KB Output is correct
71 Correct 143 ms 5328 KB Output is correct
72 Correct 137 ms 4180 KB Output is correct
73 Correct 136 ms 4180 KB Output is correct
74 Correct 250 ms 5860 KB Output is correct
75 Correct 201 ms 5608 KB Output is correct
76 Correct 271 ms 5856 KB Output is correct
77 Correct 275 ms 6092 KB Output is correct