Submission #337573

# Submission time Handle Problem Language Result Execution time Memory
337573 2020-12-21T06:31:20 Z boykut Bootfall (IZhO17_bootfall) C++14
100 / 100
406 ms 3692 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 500 * 500 + 1;
int dp[MAXN], used[MAXN], a[500], sum;

signed main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   
   int n;
   cin >> n;
   
   dp[0] = 1;
   for (int i = 0; i < n; i++) {
      cin >> a[i];
      for (int x = sum; x >= 0; x--) {
         dp[x + a[i]] += dp[x];
      }
      sum += a[i];
   }
   
   if (sum % 2 == 1 || dp[sum / 2] == 0) {
      cout << "0\n";
   } else {
      fill (used, used + MAXN, 1);
      
      for (int i = 0; i < n; i++) {
         sum -= a[i];
         for (int x = 0; x <= sum; x++) {
            dp[x + a[i]] -= dp[x];
         }
         
         for (int half = 1; half < MAXN; half++) {
            if ((sum + half) % 2 == 1 || dp[(sum + half) / 2] == 0)
               used[half] = 0;
         }
         
         for (int x = sum; x >= 0; x--) {
            dp[x + a[i]] += dp[x];
         }
         sum += a[i];
      }
      
      vector <int> ans;
      
      for (int half = 1; half < MAXN; half++) {
         if (used[half])
            ans.push_back(half);
      }
      
      cout << ans.size() << '\n';
      for (int i = 0; i < ans.size(); i++)
         cout << ans[i] << ' ';
      cout << '\n';
   }
   return 0;
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:54:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |       for (int i = 0; i < ans.size(); i++)
      |                       ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1260 KB Output is correct
2 Correct 5 ms 1260 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 4 ms 1260 KB Output is correct
5 Correct 7 ms 1280 KB Output is correct
6 Correct 5 ms 1260 KB Output is correct
7 Correct 4 ms 1260 KB Output is correct
8 Correct 8 ms 1388 KB Output is correct
9 Correct 6 ms 1260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1260 KB Output is correct
2 Correct 5 ms 1260 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 4 ms 1260 KB Output is correct
5 Correct 7 ms 1280 KB Output is correct
6 Correct 5 ms 1260 KB Output is correct
7 Correct 4 ms 1260 KB Output is correct
8 Correct 8 ms 1388 KB Output is correct
9 Correct 6 ms 1260 KB Output is correct
10 Correct 13 ms 1260 KB Output is correct
11 Correct 14 ms 1388 KB Output is correct
12 Correct 16 ms 1260 KB Output is correct
13 Correct 12 ms 1280 KB Output is correct
14 Correct 13 ms 1260 KB Output is correct
15 Correct 13 ms 1260 KB Output is correct
16 Correct 15 ms 1260 KB Output is correct
17 Correct 9 ms 1260 KB Output is correct
18 Correct 11 ms 1260 KB Output is correct
19 Correct 12 ms 1260 KB Output is correct
20 Correct 16 ms 1260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1260 KB Output is correct
2 Correct 5 ms 1260 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 4 ms 1260 KB Output is correct
5 Correct 7 ms 1280 KB Output is correct
6 Correct 5 ms 1260 KB Output is correct
7 Correct 4 ms 1260 KB Output is correct
8 Correct 8 ms 1388 KB Output is correct
9 Correct 6 ms 1260 KB Output is correct
10 Correct 13 ms 1260 KB Output is correct
11 Correct 14 ms 1388 KB Output is correct
12 Correct 16 ms 1260 KB Output is correct
13 Correct 12 ms 1280 KB Output is correct
14 Correct 13 ms 1260 KB Output is correct
15 Correct 13 ms 1260 KB Output is correct
16 Correct 15 ms 1260 KB Output is correct
17 Correct 9 ms 1260 KB Output is correct
18 Correct 11 ms 1260 KB Output is correct
19 Correct 12 ms 1260 KB Output is correct
20 Correct 16 ms 1260 KB Output is correct
21 Correct 27 ms 1388 KB Output is correct
22 Correct 31 ms 1388 KB Output is correct
23 Correct 21 ms 1388 KB Output is correct
24 Correct 38 ms 1388 KB Output is correct
25 Correct 42 ms 1388 KB Output is correct
26 Correct 42 ms 1388 KB Output is correct
27 Correct 41 ms 1516 KB Output is correct
28 Correct 41 ms 1388 KB Output is correct
29 Correct 41 ms 1388 KB Output is correct
30 Correct 41 ms 1388 KB Output is correct
31 Correct 44 ms 1516 KB Output is correct
32 Correct 41 ms 1388 KB Output is correct
33 Correct 41 ms 1388 KB Output is correct
34 Correct 43 ms 1408 KB Output is correct
35 Correct 42 ms 1388 KB Output is correct
36 Correct 41 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1260 KB Output is correct
2 Correct 5 ms 1260 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 4 ms 1260 KB Output is correct
5 Correct 7 ms 1280 KB Output is correct
6 Correct 5 ms 1260 KB Output is correct
7 Correct 4 ms 1260 KB Output is correct
8 Correct 8 ms 1388 KB Output is correct
9 Correct 6 ms 1260 KB Output is correct
10 Correct 13 ms 1260 KB Output is correct
11 Correct 14 ms 1388 KB Output is correct
12 Correct 16 ms 1260 KB Output is correct
13 Correct 12 ms 1280 KB Output is correct
14 Correct 13 ms 1260 KB Output is correct
15 Correct 13 ms 1260 KB Output is correct
16 Correct 15 ms 1260 KB Output is correct
17 Correct 9 ms 1260 KB Output is correct
18 Correct 11 ms 1260 KB Output is correct
19 Correct 12 ms 1260 KB Output is correct
20 Correct 16 ms 1260 KB Output is correct
21 Correct 27 ms 1388 KB Output is correct
22 Correct 31 ms 1388 KB Output is correct
23 Correct 21 ms 1388 KB Output is correct
24 Correct 38 ms 1388 KB Output is correct
25 Correct 42 ms 1388 KB Output is correct
26 Correct 42 ms 1388 KB Output is correct
27 Correct 41 ms 1516 KB Output is correct
28 Correct 41 ms 1388 KB Output is correct
29 Correct 41 ms 1388 KB Output is correct
30 Correct 41 ms 1388 KB Output is correct
31 Correct 44 ms 1516 KB Output is correct
32 Correct 41 ms 1388 KB Output is correct
33 Correct 41 ms 1388 KB Output is correct
34 Correct 43 ms 1408 KB Output is correct
35 Correct 42 ms 1388 KB Output is correct
36 Correct 41 ms 1388 KB Output is correct
37 Correct 85 ms 1516 KB Output is correct
38 Correct 86 ms 1516 KB Output is correct
39 Correct 116 ms 1516 KB Output is correct
40 Correct 120 ms 1760 KB Output is correct
41 Correct 129 ms 1644 KB Output is correct
42 Correct 113 ms 1648 KB Output is correct
43 Correct 120 ms 1912 KB Output is correct
44 Correct 121 ms 1900 KB Output is correct
45 Correct 124 ms 1920 KB Output is correct
46 Correct 119 ms 1388 KB Output is correct
47 Correct 113 ms 1644 KB Output is correct
48 Correct 123 ms 1900 KB Output is correct
49 Correct 121 ms 1644 KB Output is correct
50 Correct 114 ms 1636 KB Output is correct
51 Correct 3 ms 492 KB Output is correct
52 Correct 139 ms 2036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1260 KB Output is correct
2 Correct 5 ms 1260 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 4 ms 1260 KB Output is correct
5 Correct 7 ms 1280 KB Output is correct
6 Correct 5 ms 1260 KB Output is correct
7 Correct 4 ms 1260 KB Output is correct
8 Correct 8 ms 1388 KB Output is correct
9 Correct 6 ms 1260 KB Output is correct
10 Correct 13 ms 1260 KB Output is correct
11 Correct 14 ms 1388 KB Output is correct
12 Correct 16 ms 1260 KB Output is correct
13 Correct 12 ms 1280 KB Output is correct
14 Correct 13 ms 1260 KB Output is correct
15 Correct 13 ms 1260 KB Output is correct
16 Correct 15 ms 1260 KB Output is correct
17 Correct 9 ms 1260 KB Output is correct
18 Correct 11 ms 1260 KB Output is correct
19 Correct 12 ms 1260 KB Output is correct
20 Correct 16 ms 1260 KB Output is correct
21 Correct 27 ms 1388 KB Output is correct
22 Correct 31 ms 1388 KB Output is correct
23 Correct 21 ms 1388 KB Output is correct
24 Correct 38 ms 1388 KB Output is correct
25 Correct 42 ms 1388 KB Output is correct
26 Correct 42 ms 1388 KB Output is correct
27 Correct 41 ms 1516 KB Output is correct
28 Correct 41 ms 1388 KB Output is correct
29 Correct 41 ms 1388 KB Output is correct
30 Correct 41 ms 1388 KB Output is correct
31 Correct 44 ms 1516 KB Output is correct
32 Correct 41 ms 1388 KB Output is correct
33 Correct 41 ms 1388 KB Output is correct
34 Correct 43 ms 1408 KB Output is correct
35 Correct 42 ms 1388 KB Output is correct
36 Correct 41 ms 1388 KB Output is correct
37 Correct 85 ms 1516 KB Output is correct
38 Correct 86 ms 1516 KB Output is correct
39 Correct 116 ms 1516 KB Output is correct
40 Correct 120 ms 1760 KB Output is correct
41 Correct 129 ms 1644 KB Output is correct
42 Correct 113 ms 1648 KB Output is correct
43 Correct 120 ms 1912 KB Output is correct
44 Correct 121 ms 1900 KB Output is correct
45 Correct 124 ms 1920 KB Output is correct
46 Correct 119 ms 1388 KB Output is correct
47 Correct 113 ms 1644 KB Output is correct
48 Correct 123 ms 1900 KB Output is correct
49 Correct 121 ms 1644 KB Output is correct
50 Correct 114 ms 1636 KB Output is correct
51 Correct 3 ms 492 KB Output is correct
52 Correct 139 ms 2036 KB Output is correct
53 Correct 140 ms 1900 KB Output is correct
54 Correct 170 ms 1900 KB Output is correct
55 Correct 206 ms 2576 KB Output is correct
56 Correct 148 ms 1900 KB Output is correct
57 Correct 214 ms 2544 KB Output is correct
58 Correct 173 ms 2048 KB Output is correct
59 Correct 185 ms 2160 KB Output is correct
60 Correct 6 ms 620 KB Output is correct
61 Correct 189 ms 2160 KB Output is correct
62 Correct 181 ms 2288 KB Output is correct
63 Correct 184 ms 2416 KB Output is correct
64 Correct 178 ms 2288 KB Output is correct
65 Correct 147 ms 1644 KB Output is correct
66 Correct 145 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1260 KB Output is correct
2 Correct 5 ms 1260 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 4 ms 1260 KB Output is correct
5 Correct 7 ms 1280 KB Output is correct
6 Correct 5 ms 1260 KB Output is correct
7 Correct 4 ms 1260 KB Output is correct
8 Correct 8 ms 1388 KB Output is correct
9 Correct 6 ms 1260 KB Output is correct
10 Correct 13 ms 1260 KB Output is correct
11 Correct 14 ms 1388 KB Output is correct
12 Correct 16 ms 1260 KB Output is correct
13 Correct 12 ms 1280 KB Output is correct
14 Correct 13 ms 1260 KB Output is correct
15 Correct 13 ms 1260 KB Output is correct
16 Correct 15 ms 1260 KB Output is correct
17 Correct 9 ms 1260 KB Output is correct
18 Correct 11 ms 1260 KB Output is correct
19 Correct 12 ms 1260 KB Output is correct
20 Correct 16 ms 1260 KB Output is correct
21 Correct 27 ms 1388 KB Output is correct
22 Correct 31 ms 1388 KB Output is correct
23 Correct 21 ms 1388 KB Output is correct
24 Correct 38 ms 1388 KB Output is correct
25 Correct 42 ms 1388 KB Output is correct
26 Correct 42 ms 1388 KB Output is correct
27 Correct 41 ms 1516 KB Output is correct
28 Correct 41 ms 1388 KB Output is correct
29 Correct 41 ms 1388 KB Output is correct
30 Correct 41 ms 1388 KB Output is correct
31 Correct 44 ms 1516 KB Output is correct
32 Correct 41 ms 1388 KB Output is correct
33 Correct 41 ms 1388 KB Output is correct
34 Correct 43 ms 1408 KB Output is correct
35 Correct 42 ms 1388 KB Output is correct
36 Correct 41 ms 1388 KB Output is correct
37 Correct 85 ms 1516 KB Output is correct
38 Correct 86 ms 1516 KB Output is correct
39 Correct 116 ms 1516 KB Output is correct
40 Correct 120 ms 1760 KB Output is correct
41 Correct 129 ms 1644 KB Output is correct
42 Correct 113 ms 1648 KB Output is correct
43 Correct 120 ms 1912 KB Output is correct
44 Correct 121 ms 1900 KB Output is correct
45 Correct 124 ms 1920 KB Output is correct
46 Correct 119 ms 1388 KB Output is correct
47 Correct 113 ms 1644 KB Output is correct
48 Correct 123 ms 1900 KB Output is correct
49 Correct 121 ms 1644 KB Output is correct
50 Correct 114 ms 1636 KB Output is correct
51 Correct 3 ms 492 KB Output is correct
52 Correct 139 ms 2036 KB Output is correct
53 Correct 140 ms 1900 KB Output is correct
54 Correct 170 ms 1900 KB Output is correct
55 Correct 206 ms 2576 KB Output is correct
56 Correct 148 ms 1900 KB Output is correct
57 Correct 214 ms 2544 KB Output is correct
58 Correct 173 ms 2048 KB Output is correct
59 Correct 185 ms 2160 KB Output is correct
60 Correct 6 ms 620 KB Output is correct
61 Correct 189 ms 2160 KB Output is correct
62 Correct 181 ms 2288 KB Output is correct
63 Correct 184 ms 2416 KB Output is correct
64 Correct 178 ms 2288 KB Output is correct
65 Correct 147 ms 1644 KB Output is correct
66 Correct 145 ms 1644 KB Output is correct
67 Correct 209 ms 2288 KB Output is correct
68 Correct 17 ms 876 KB Output is correct
69 Correct 379 ms 3356 KB Output is correct
70 Correct 309 ms 2672 KB Output is correct
71 Correct 304 ms 2672 KB Output is correct
72 Correct 300 ms 1772 KB Output is correct
73 Correct 296 ms 1900 KB Output is correct
74 Correct 393 ms 3436 KB Output is correct
75 Correct 346 ms 3052 KB Output is correct
76 Correct 406 ms 3436 KB Output is correct
77 Correct 400 ms 3692 KB Output is correct