Submission #522900

# Submission time Handle Problem Language Result Execution time Memory
522900 2022-02-06T11:21:52 Z Nursik Bootfall (IZhO17_bootfall) C++14
100 / 100
838 ms 8136 KB
#include <bits/stdc++.h>

#define pb push_back
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair

const ll maxn = 5e2 + 1, maxm = 3e5 + 1,  maxk = 61;
const ll inf = 1000000000, mod = inf + 7, mod2 = 998244353;
const ll pa = 31, block = 400;

using namespace std;

ll n, sum;
unsigned ll a[maxn], dp[maxm], cnt[maxm], ans[maxm];
int main(){
  //  ios_base::sync_with_stdio(false);
   // cin.tie(0), cout.tie(0);
    cin >> n;
    dp[0] = 1;
    for (int i = 1; i <= n; ++i){
        cin >> a[i];
        for(int j = maxm - 1; j >= a[i]; j--)
            dp[j] = (dp[j] + dp[j - a[i]]) % mod;
        sum += a[i];
    }
    if (sum % 2 != 0 || dp[sum / 2] == 0){
        cout << 0;
        return 0;
    }
    for (int i = 1; i <= n; ++i){
        for (int j = a[i]; j <= maxm - 1; ++j){
            dp[j] = (dp[j] - dp[j - a[i]] + mod) % mod;
        }
        for (int j = 0; j <= maxm - 1; ++j){
            if (dp[j] > 0){
                int f = j, s = sum - a[i] - j;
                int rz = abs(f - s);
                cnt[rz] = 1;
            }
        }
        for (int j = 0; j <= maxm - 1; ++j){
            if (cnt[j] > 0){
                ans[j]++;
            }
            cnt[j] = 0;
        }
        for (int j = maxm - 1; j >= a[i]; --j){
            dp[j] = (dp[j] + dp[j - a[i]]) % mod;
        }
    }
    vector<int> v;
    for (int i = 1; i <= maxm - 1; ++i){
        if (ans[i] == n){
            v.pb(i);
        }
    }
    cout << v.size() << '\n';
    for (auto it : v){
        cout << it << " ";
    }
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:25:33: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   25 |         for(int j = maxm - 1; j >= a[i]; j--)
      |                               ~~^~~~~~~
bootfall.cpp:50:34: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   50 |         for (int j = maxm - 1; j >= a[i]; --j){
      |                                ~~^~~~~~~
bootfall.cpp:56:20: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
   56 |         if (ans[i] == n){
      |             ~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4940 KB Output is correct
2 Correct 14 ms 4996 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 10 ms 4940 KB Output is correct
5 Correct 23 ms 5004 KB Output is correct
6 Correct 16 ms 4996 KB Output is correct
7 Correct 14 ms 4996 KB Output is correct
8 Correct 22 ms 4940 KB Output is correct
9 Correct 19 ms 5000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4940 KB Output is correct
2 Correct 14 ms 4996 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 10 ms 4940 KB Output is correct
5 Correct 23 ms 5004 KB Output is correct
6 Correct 16 ms 4996 KB Output is correct
7 Correct 14 ms 4996 KB Output is correct
8 Correct 22 ms 4940 KB Output is correct
9 Correct 19 ms 5000 KB Output is correct
10 Correct 62 ms 4980 KB Output is correct
11 Correct 54 ms 4940 KB Output is correct
12 Correct 48 ms 4940 KB Output is correct
13 Correct 49 ms 4988 KB Output is correct
14 Correct 47 ms 4948 KB Output is correct
15 Correct 55 ms 4940 KB Output is correct
16 Correct 56 ms 4972 KB Output is correct
17 Correct 36 ms 4984 KB Output is correct
18 Correct 49 ms 5068 KB Output is correct
19 Correct 51 ms 4992 KB Output is correct
20 Correct 52 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4940 KB Output is correct
2 Correct 14 ms 4996 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 10 ms 4940 KB Output is correct
5 Correct 23 ms 5004 KB Output is correct
6 Correct 16 ms 4996 KB Output is correct
7 Correct 14 ms 4996 KB Output is correct
8 Correct 22 ms 4940 KB Output is correct
9 Correct 19 ms 5000 KB Output is correct
10 Correct 62 ms 4980 KB Output is correct
11 Correct 54 ms 4940 KB Output is correct
12 Correct 48 ms 4940 KB Output is correct
13 Correct 49 ms 4988 KB Output is correct
14 Correct 47 ms 4948 KB Output is correct
15 Correct 55 ms 4940 KB Output is correct
16 Correct 56 ms 4972 KB Output is correct
17 Correct 36 ms 4984 KB Output is correct
18 Correct 49 ms 5068 KB Output is correct
19 Correct 51 ms 4992 KB Output is correct
20 Correct 52 ms 4992 KB Output is correct
21 Correct 106 ms 4948 KB Output is correct
22 Correct 130 ms 5004 KB Output is correct
23 Correct 84 ms 4992 KB Output is correct
24 Correct 151 ms 4940 KB Output is correct
25 Correct 153 ms 5060 KB Output is correct
26 Correct 185 ms 5052 KB Output is correct
27 Correct 173 ms 5056 KB Output is correct
28 Correct 149 ms 5056 KB Output is correct
29 Correct 158 ms 5048 KB Output is correct
30 Correct 220 ms 5012 KB Output is correct
31 Correct 151 ms 5056 KB Output is correct
32 Correct 154 ms 5016 KB Output is correct
33 Correct 158 ms 5056 KB Output is correct
34 Correct 174 ms 5068 KB Output is correct
35 Correct 150 ms 4944 KB Output is correct
36 Correct 165 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4940 KB Output is correct
2 Correct 14 ms 4996 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 10 ms 4940 KB Output is correct
5 Correct 23 ms 5004 KB Output is correct
6 Correct 16 ms 4996 KB Output is correct
7 Correct 14 ms 4996 KB Output is correct
8 Correct 22 ms 4940 KB Output is correct
9 Correct 19 ms 5000 KB Output is correct
10 Correct 62 ms 4980 KB Output is correct
11 Correct 54 ms 4940 KB Output is correct
12 Correct 48 ms 4940 KB Output is correct
13 Correct 49 ms 4988 KB Output is correct
14 Correct 47 ms 4948 KB Output is correct
15 Correct 55 ms 4940 KB Output is correct
16 Correct 56 ms 4972 KB Output is correct
17 Correct 36 ms 4984 KB Output is correct
18 Correct 49 ms 5068 KB Output is correct
19 Correct 51 ms 4992 KB Output is correct
20 Correct 52 ms 4992 KB Output is correct
21 Correct 106 ms 4948 KB Output is correct
22 Correct 130 ms 5004 KB Output is correct
23 Correct 84 ms 4992 KB Output is correct
24 Correct 151 ms 4940 KB Output is correct
25 Correct 153 ms 5060 KB Output is correct
26 Correct 185 ms 5052 KB Output is correct
27 Correct 173 ms 5056 KB Output is correct
28 Correct 149 ms 5056 KB Output is correct
29 Correct 158 ms 5048 KB Output is correct
30 Correct 220 ms 5012 KB Output is correct
31 Correct 151 ms 5056 KB Output is correct
32 Correct 154 ms 5016 KB Output is correct
33 Correct 158 ms 5056 KB Output is correct
34 Correct 174 ms 5068 KB Output is correct
35 Correct 150 ms 4944 KB Output is correct
36 Correct 165 ms 4940 KB Output is correct
37 Correct 353 ms 5320 KB Output is correct
38 Correct 316 ms 5260 KB Output is correct
39 Correct 375 ms 5460 KB Output is correct
40 Correct 417 ms 5444 KB Output is correct
41 Correct 419 ms 5520 KB Output is correct
42 Correct 425 ms 5324 KB Output is correct
43 Correct 405 ms 5716 KB Output is correct
44 Correct 380 ms 5696 KB Output is correct
45 Correct 431 ms 5824 KB Output is correct
46 Correct 411 ms 5224 KB Output is correct
47 Correct 415 ms 5360 KB Output is correct
48 Correct 383 ms 5716 KB Output is correct
49 Correct 446 ms 5460 KB Output is correct
50 Correct 384 ms 5360 KB Output is correct
51 Correct 81 ms 2636 KB Output is correct
52 Correct 434 ms 5828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4940 KB Output is correct
2 Correct 14 ms 4996 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 10 ms 4940 KB Output is correct
5 Correct 23 ms 5004 KB Output is correct
6 Correct 16 ms 4996 KB Output is correct
7 Correct 14 ms 4996 KB Output is correct
8 Correct 22 ms 4940 KB Output is correct
9 Correct 19 ms 5000 KB Output is correct
10 Correct 62 ms 4980 KB Output is correct
11 Correct 54 ms 4940 KB Output is correct
12 Correct 48 ms 4940 KB Output is correct
13 Correct 49 ms 4988 KB Output is correct
14 Correct 47 ms 4948 KB Output is correct
15 Correct 55 ms 4940 KB Output is correct
16 Correct 56 ms 4972 KB Output is correct
17 Correct 36 ms 4984 KB Output is correct
18 Correct 49 ms 5068 KB Output is correct
19 Correct 51 ms 4992 KB Output is correct
20 Correct 52 ms 4992 KB Output is correct
21 Correct 106 ms 4948 KB Output is correct
22 Correct 130 ms 5004 KB Output is correct
23 Correct 84 ms 4992 KB Output is correct
24 Correct 151 ms 4940 KB Output is correct
25 Correct 153 ms 5060 KB Output is correct
26 Correct 185 ms 5052 KB Output is correct
27 Correct 173 ms 5056 KB Output is correct
28 Correct 149 ms 5056 KB Output is correct
29 Correct 158 ms 5048 KB Output is correct
30 Correct 220 ms 5012 KB Output is correct
31 Correct 151 ms 5056 KB Output is correct
32 Correct 154 ms 5016 KB Output is correct
33 Correct 158 ms 5056 KB Output is correct
34 Correct 174 ms 5068 KB Output is correct
35 Correct 150 ms 4944 KB Output is correct
36 Correct 165 ms 4940 KB Output is correct
37 Correct 353 ms 5320 KB Output is correct
38 Correct 316 ms 5260 KB Output is correct
39 Correct 375 ms 5460 KB Output is correct
40 Correct 417 ms 5444 KB Output is correct
41 Correct 419 ms 5520 KB Output is correct
42 Correct 425 ms 5324 KB Output is correct
43 Correct 405 ms 5716 KB Output is correct
44 Correct 380 ms 5696 KB Output is correct
45 Correct 431 ms 5824 KB Output is correct
46 Correct 411 ms 5224 KB Output is correct
47 Correct 415 ms 5360 KB Output is correct
48 Correct 383 ms 5716 KB Output is correct
49 Correct 446 ms 5460 KB Output is correct
50 Correct 384 ms 5360 KB Output is correct
51 Correct 81 ms 2636 KB Output is correct
52 Correct 434 ms 5828 KB Output is correct
53 Correct 521 ms 5584 KB Output is correct
54 Correct 592 ms 5792 KB Output is correct
55 Correct 555 ms 6348 KB Output is correct
56 Correct 552 ms 5804 KB Output is correct
57 Correct 550 ms 6524 KB Output is correct
58 Correct 564 ms 5956 KB Output is correct
59 Correct 544 ms 6080 KB Output is correct
60 Correct 108 ms 2636 KB Output is correct
61 Correct 549 ms 6204 KB Output is correct
62 Correct 573 ms 6204 KB Output is correct
63 Correct 517 ms 6296 KB Output is correct
64 Correct 493 ms 6336 KB Output is correct
65 Correct 472 ms 5360 KB Output is correct
66 Correct 484 ms 5396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4940 KB Output is correct
2 Correct 14 ms 4996 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 10 ms 4940 KB Output is correct
5 Correct 23 ms 5004 KB Output is correct
6 Correct 16 ms 4996 KB Output is correct
7 Correct 14 ms 4996 KB Output is correct
8 Correct 22 ms 4940 KB Output is correct
9 Correct 19 ms 5000 KB Output is correct
10 Correct 62 ms 4980 KB Output is correct
11 Correct 54 ms 4940 KB Output is correct
12 Correct 48 ms 4940 KB Output is correct
13 Correct 49 ms 4988 KB Output is correct
14 Correct 47 ms 4948 KB Output is correct
15 Correct 55 ms 4940 KB Output is correct
16 Correct 56 ms 4972 KB Output is correct
17 Correct 36 ms 4984 KB Output is correct
18 Correct 49 ms 5068 KB Output is correct
19 Correct 51 ms 4992 KB Output is correct
20 Correct 52 ms 4992 KB Output is correct
21 Correct 106 ms 4948 KB Output is correct
22 Correct 130 ms 5004 KB Output is correct
23 Correct 84 ms 4992 KB Output is correct
24 Correct 151 ms 4940 KB Output is correct
25 Correct 153 ms 5060 KB Output is correct
26 Correct 185 ms 5052 KB Output is correct
27 Correct 173 ms 5056 KB Output is correct
28 Correct 149 ms 5056 KB Output is correct
29 Correct 158 ms 5048 KB Output is correct
30 Correct 220 ms 5012 KB Output is correct
31 Correct 151 ms 5056 KB Output is correct
32 Correct 154 ms 5016 KB Output is correct
33 Correct 158 ms 5056 KB Output is correct
34 Correct 174 ms 5068 KB Output is correct
35 Correct 150 ms 4944 KB Output is correct
36 Correct 165 ms 4940 KB Output is correct
37 Correct 353 ms 5320 KB Output is correct
38 Correct 316 ms 5260 KB Output is correct
39 Correct 375 ms 5460 KB Output is correct
40 Correct 417 ms 5444 KB Output is correct
41 Correct 419 ms 5520 KB Output is correct
42 Correct 425 ms 5324 KB Output is correct
43 Correct 405 ms 5716 KB Output is correct
44 Correct 380 ms 5696 KB Output is correct
45 Correct 431 ms 5824 KB Output is correct
46 Correct 411 ms 5224 KB Output is correct
47 Correct 415 ms 5360 KB Output is correct
48 Correct 383 ms 5716 KB Output is correct
49 Correct 446 ms 5460 KB Output is correct
50 Correct 384 ms 5360 KB Output is correct
51 Correct 81 ms 2636 KB Output is correct
52 Correct 434 ms 5828 KB Output is correct
53 Correct 521 ms 5584 KB Output is correct
54 Correct 592 ms 5792 KB Output is correct
55 Correct 555 ms 6348 KB Output is correct
56 Correct 552 ms 5804 KB Output is correct
57 Correct 550 ms 6524 KB Output is correct
58 Correct 564 ms 5956 KB Output is correct
59 Correct 544 ms 6080 KB Output is correct
60 Correct 108 ms 2636 KB Output is correct
61 Correct 549 ms 6204 KB Output is correct
62 Correct 573 ms 6204 KB Output is correct
63 Correct 517 ms 6296 KB Output is correct
64 Correct 493 ms 6336 KB Output is correct
65 Correct 472 ms 5360 KB Output is correct
66 Correct 484 ms 5396 KB Output is correct
67 Correct 615 ms 6220 KB Output is correct
68 Correct 157 ms 2636 KB Output is correct
69 Correct 810 ms 7868 KB Output is correct
70 Correct 782 ms 6740 KB Output is correct
71 Correct 838 ms 6592 KB Output is correct
72 Correct 769 ms 5836 KB Output is correct
73 Correct 774 ms 5956 KB Output is correct
74 Correct 814 ms 7868 KB Output is correct
75 Correct 791 ms 7352 KB Output is correct
76 Correct 834 ms 8008 KB Output is correct
77 Correct 807 ms 8136 KB Output is correct