Submission #199928

# Submission time Handle Problem Language Result Execution time Memory
199928 2020-02-04T06:18:02 Z quocnguyen1012 Bootfall (IZhO17_bootfall) C++14
100 / 100
553 ms 3448 KB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;

const int maxn = 505, mod = 1e9 + 7;

int N, a[maxn];
int f[maxn * maxn];
vector<int> ret;

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  if (fopen("A.INP", "r")){
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  }
  cin >> N;
  int sum = 0;
  f[0] = 1;
  for (int i = 1; i <= N; ++i){
    cin >> a[i];
    sum += a[i];
    for (int j = sum; j >= a[i]; --j){
      f[j] += f[j - a[i]];
      f[j] %= mod;
    }
  }
  if (sum & 1 || f[sum / 2] == 0){
    cout << "0";
    return 0;
  }
  for (int i = 1; i < maxn * maxn; ++i){
    ret.pb(i);
  }
  for (int i = 1; i <= N; ++i){
    for (int j = a[i]; j <= sum; ++j){
      f[j] -= f[j - a[i]];
      if (f[j] < 0) f[j] += mod;
    }
    vector<int> vi;
    for (auto & all : ret){
      int val = sum - a[i] + all;
      if (val < 0 || val % 2 == 1 || f[val / 2] == 0){
        continue;
      }
      vi.pb(all);
    }
    swap(vi, ret);
    for (int j = sum; j >= a[i]; --j){
      f[j] += f[j - a[i]];
      f[j] %= mod;
    }
  }
  cout << ret.size() << '\n';
  for (auto & it : ret) cout << it << ' ' ;
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:21:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("A.INP", "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:22:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("A.OUT", "w", stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1524 KB Output is correct
2 Correct 8 ms 1524 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 7 ms 1524 KB Output is correct
5 Correct 8 ms 1524 KB Output is correct
6 Correct 7 ms 1524 KB Output is correct
7 Correct 7 ms 1524 KB Output is correct
8 Correct 7 ms 1524 KB Output is correct
9 Correct 7 ms 1524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1524 KB Output is correct
2 Correct 8 ms 1524 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 7 ms 1524 KB Output is correct
5 Correct 8 ms 1524 KB Output is correct
6 Correct 7 ms 1524 KB Output is correct
7 Correct 7 ms 1524 KB Output is correct
8 Correct 7 ms 1524 KB Output is correct
9 Correct 7 ms 1524 KB Output is correct
10 Correct 7 ms 1524 KB Output is correct
11 Correct 8 ms 1524 KB Output is correct
12 Correct 7 ms 1524 KB Output is correct
13 Correct 8 ms 1524 KB Output is correct
14 Correct 7 ms 1648 KB Output is correct
15 Correct 7 ms 1524 KB Output is correct
16 Correct 7 ms 1524 KB Output is correct
17 Correct 7 ms 1524 KB Output is correct
18 Correct 7 ms 1524 KB Output is correct
19 Correct 7 ms 1524 KB Output is correct
20 Correct 9 ms 1520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1524 KB Output is correct
2 Correct 8 ms 1524 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 7 ms 1524 KB Output is correct
5 Correct 8 ms 1524 KB Output is correct
6 Correct 7 ms 1524 KB Output is correct
7 Correct 7 ms 1524 KB Output is correct
8 Correct 7 ms 1524 KB Output is correct
9 Correct 7 ms 1524 KB Output is correct
10 Correct 7 ms 1524 KB Output is correct
11 Correct 8 ms 1524 KB Output is correct
12 Correct 7 ms 1524 KB Output is correct
13 Correct 8 ms 1524 KB Output is correct
14 Correct 7 ms 1648 KB Output is correct
15 Correct 7 ms 1524 KB Output is correct
16 Correct 7 ms 1524 KB Output is correct
17 Correct 7 ms 1524 KB Output is correct
18 Correct 7 ms 1524 KB Output is correct
19 Correct 7 ms 1524 KB Output is correct
20 Correct 9 ms 1520 KB Output is correct
21 Correct 8 ms 1524 KB Output is correct
22 Correct 8 ms 1524 KB Output is correct
23 Correct 8 ms 1524 KB Output is correct
24 Correct 9 ms 1524 KB Output is correct
25 Correct 11 ms 1524 KB Output is correct
26 Correct 11 ms 1524 KB Output is correct
27 Correct 11 ms 1524 KB Output is correct
28 Correct 11 ms 1524 KB Output is correct
29 Correct 13 ms 1520 KB Output is correct
30 Correct 9 ms 1524 KB Output is correct
31 Correct 11 ms 1524 KB Output is correct
32 Correct 10 ms 1524 KB Output is correct
33 Correct 11 ms 1524 KB Output is correct
34 Correct 10 ms 1524 KB Output is correct
35 Correct 11 ms 1524 KB Output is correct
36 Correct 9 ms 1524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1524 KB Output is correct
2 Correct 8 ms 1524 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 7 ms 1524 KB Output is correct
5 Correct 8 ms 1524 KB Output is correct
6 Correct 7 ms 1524 KB Output is correct
7 Correct 7 ms 1524 KB Output is correct
8 Correct 7 ms 1524 KB Output is correct
9 Correct 7 ms 1524 KB Output is correct
10 Correct 7 ms 1524 KB Output is correct
11 Correct 8 ms 1524 KB Output is correct
12 Correct 7 ms 1524 KB Output is correct
13 Correct 8 ms 1524 KB Output is correct
14 Correct 7 ms 1648 KB Output is correct
15 Correct 7 ms 1524 KB Output is correct
16 Correct 7 ms 1524 KB Output is correct
17 Correct 7 ms 1524 KB Output is correct
18 Correct 7 ms 1524 KB Output is correct
19 Correct 7 ms 1524 KB Output is correct
20 Correct 9 ms 1520 KB Output is correct
21 Correct 8 ms 1524 KB Output is correct
22 Correct 8 ms 1524 KB Output is correct
23 Correct 8 ms 1524 KB Output is correct
24 Correct 9 ms 1524 KB Output is correct
25 Correct 11 ms 1524 KB Output is correct
26 Correct 11 ms 1524 KB Output is correct
27 Correct 11 ms 1524 KB Output is correct
28 Correct 11 ms 1524 KB Output is correct
29 Correct 13 ms 1520 KB Output is correct
30 Correct 9 ms 1524 KB Output is correct
31 Correct 11 ms 1524 KB Output is correct
32 Correct 10 ms 1524 KB Output is correct
33 Correct 11 ms 1524 KB Output is correct
34 Correct 10 ms 1524 KB Output is correct
35 Correct 11 ms 1524 KB Output is correct
36 Correct 9 ms 1524 KB Output is correct
37 Correct 27 ms 1524 KB Output is correct
38 Correct 26 ms 1524 KB Output is correct
39 Correct 62 ms 1780 KB Output is correct
40 Correct 51 ms 1652 KB Output is correct
41 Correct 74 ms 1776 KB Output is correct
42 Correct 42 ms 1652 KB Output is correct
43 Correct 73 ms 1780 KB Output is correct
44 Correct 71 ms 1780 KB Output is correct
45 Correct 75 ms 1776 KB Output is correct
46 Correct 36 ms 1652 KB Output is correct
47 Correct 45 ms 1652 KB Output is correct
48 Correct 71 ms 1780 KB Output is correct
49 Correct 72 ms 1780 KB Output is correct
50 Correct 46 ms 1652 KB Output is correct
51 Correct 13 ms 504 KB Output is correct
52 Correct 90 ms 1904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1524 KB Output is correct
2 Correct 8 ms 1524 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 7 ms 1524 KB Output is correct
5 Correct 8 ms 1524 KB Output is correct
6 Correct 7 ms 1524 KB Output is correct
7 Correct 7 ms 1524 KB Output is correct
8 Correct 7 ms 1524 KB Output is correct
9 Correct 7 ms 1524 KB Output is correct
10 Correct 7 ms 1524 KB Output is correct
11 Correct 8 ms 1524 KB Output is correct
12 Correct 7 ms 1524 KB Output is correct
13 Correct 8 ms 1524 KB Output is correct
14 Correct 7 ms 1648 KB Output is correct
15 Correct 7 ms 1524 KB Output is correct
16 Correct 7 ms 1524 KB Output is correct
17 Correct 7 ms 1524 KB Output is correct
18 Correct 7 ms 1524 KB Output is correct
19 Correct 7 ms 1524 KB Output is correct
20 Correct 9 ms 1520 KB Output is correct
21 Correct 8 ms 1524 KB Output is correct
22 Correct 8 ms 1524 KB Output is correct
23 Correct 8 ms 1524 KB Output is correct
24 Correct 9 ms 1524 KB Output is correct
25 Correct 11 ms 1524 KB Output is correct
26 Correct 11 ms 1524 KB Output is correct
27 Correct 11 ms 1524 KB Output is correct
28 Correct 11 ms 1524 KB Output is correct
29 Correct 13 ms 1520 KB Output is correct
30 Correct 9 ms 1524 KB Output is correct
31 Correct 11 ms 1524 KB Output is correct
32 Correct 10 ms 1524 KB Output is correct
33 Correct 11 ms 1524 KB Output is correct
34 Correct 10 ms 1524 KB Output is correct
35 Correct 11 ms 1524 KB Output is correct
36 Correct 9 ms 1524 KB Output is correct
37 Correct 27 ms 1524 KB Output is correct
38 Correct 26 ms 1524 KB Output is correct
39 Correct 62 ms 1780 KB Output is correct
40 Correct 51 ms 1652 KB Output is correct
41 Correct 74 ms 1776 KB Output is correct
42 Correct 42 ms 1652 KB Output is correct
43 Correct 73 ms 1780 KB Output is correct
44 Correct 71 ms 1780 KB Output is correct
45 Correct 75 ms 1776 KB Output is correct
46 Correct 36 ms 1652 KB Output is correct
47 Correct 45 ms 1652 KB Output is correct
48 Correct 71 ms 1780 KB Output is correct
49 Correct 72 ms 1780 KB Output is correct
50 Correct 46 ms 1652 KB Output is correct
51 Correct 13 ms 504 KB Output is correct
52 Correct 90 ms 1904 KB Output is correct
53 Correct 70 ms 1776 KB Output is correct
54 Correct 100 ms 1864 KB Output is correct
55 Correct 184 ms 2288 KB Output is correct
56 Correct 84 ms 1900 KB Output is correct
57 Correct 195 ms 2288 KB Output is correct
58 Correct 107 ms 1904 KB Output is correct
59 Correct 139 ms 2024 KB Output is correct
60 Correct 22 ms 504 KB Output is correct
61 Correct 147 ms 2160 KB Output is correct
62 Correct 148 ms 2160 KB Output is correct
63 Correct 164 ms 2160 KB Output is correct
64 Correct 153 ms 2160 KB Output is correct
65 Correct 62 ms 1652 KB Output is correct
66 Correct 71 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1524 KB Output is correct
2 Correct 8 ms 1524 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 7 ms 1524 KB Output is correct
5 Correct 8 ms 1524 KB Output is correct
6 Correct 7 ms 1524 KB Output is correct
7 Correct 7 ms 1524 KB Output is correct
8 Correct 7 ms 1524 KB Output is correct
9 Correct 7 ms 1524 KB Output is correct
10 Correct 7 ms 1524 KB Output is correct
11 Correct 8 ms 1524 KB Output is correct
12 Correct 7 ms 1524 KB Output is correct
13 Correct 8 ms 1524 KB Output is correct
14 Correct 7 ms 1648 KB Output is correct
15 Correct 7 ms 1524 KB Output is correct
16 Correct 7 ms 1524 KB Output is correct
17 Correct 7 ms 1524 KB Output is correct
18 Correct 7 ms 1524 KB Output is correct
19 Correct 7 ms 1524 KB Output is correct
20 Correct 9 ms 1520 KB Output is correct
21 Correct 8 ms 1524 KB Output is correct
22 Correct 8 ms 1524 KB Output is correct
23 Correct 8 ms 1524 KB Output is correct
24 Correct 9 ms 1524 KB Output is correct
25 Correct 11 ms 1524 KB Output is correct
26 Correct 11 ms 1524 KB Output is correct
27 Correct 11 ms 1524 KB Output is correct
28 Correct 11 ms 1524 KB Output is correct
29 Correct 13 ms 1520 KB Output is correct
30 Correct 9 ms 1524 KB Output is correct
31 Correct 11 ms 1524 KB Output is correct
32 Correct 10 ms 1524 KB Output is correct
33 Correct 11 ms 1524 KB Output is correct
34 Correct 10 ms 1524 KB Output is correct
35 Correct 11 ms 1524 KB Output is correct
36 Correct 9 ms 1524 KB Output is correct
37 Correct 27 ms 1524 KB Output is correct
38 Correct 26 ms 1524 KB Output is correct
39 Correct 62 ms 1780 KB Output is correct
40 Correct 51 ms 1652 KB Output is correct
41 Correct 74 ms 1776 KB Output is correct
42 Correct 42 ms 1652 KB Output is correct
43 Correct 73 ms 1780 KB Output is correct
44 Correct 71 ms 1780 KB Output is correct
45 Correct 75 ms 1776 KB Output is correct
46 Correct 36 ms 1652 KB Output is correct
47 Correct 45 ms 1652 KB Output is correct
48 Correct 71 ms 1780 KB Output is correct
49 Correct 72 ms 1780 KB Output is correct
50 Correct 46 ms 1652 KB Output is correct
51 Correct 13 ms 504 KB Output is correct
52 Correct 90 ms 1904 KB Output is correct
53 Correct 70 ms 1776 KB Output is correct
54 Correct 100 ms 1864 KB Output is correct
55 Correct 184 ms 2288 KB Output is correct
56 Correct 84 ms 1900 KB Output is correct
57 Correct 195 ms 2288 KB Output is correct
58 Correct 107 ms 1904 KB Output is correct
59 Correct 139 ms 2024 KB Output is correct
60 Correct 22 ms 504 KB Output is correct
61 Correct 147 ms 2160 KB Output is correct
62 Correct 148 ms 2160 KB Output is correct
63 Correct 164 ms 2160 KB Output is correct
64 Correct 153 ms 2160 KB Output is correct
65 Correct 62 ms 1652 KB Output is correct
66 Correct 71 ms 1656 KB Output is correct
67 Correct 148 ms 2044 KB Output is correct
68 Correct 55 ms 760 KB Output is correct
69 Correct 493 ms 3192 KB Output is correct
70 Correct 300 ms 2416 KB Output is correct
71 Correct 294 ms 2288 KB Output is correct
72 Correct 224 ms 2412 KB Output is correct
73 Correct 220 ms 2288 KB Output is correct
74 Correct 517 ms 3444 KB Output is correct
75 Correct 409 ms 2924 KB Output is correct
76 Correct 545 ms 3324 KB Output is correct
77 Correct 553 ms 3448 KB Output is correct