Submission #679701

# Submission time Handle Problem Language Result Execution time Memory
679701 2023-01-09T01:51:35 Z vjudge1 Bootfall (IZhO17_bootfall) C++14
100 / 100
674 ms 2984 KB
#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define pb push_back
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef pair<int, int> ii;

const int N = 500 + 5;
const int mod = 1e9 + 21;

int dp[N * N];
int n, sum;
int a[N], cnt[N * N];

void fix(int &a)
{
    if(a >= mod) a -= mod;
    if(a < 0) a += mod;
}

void add(int x)
{
    for(int i = sum; i >= x; i--)
    {
        dp[i] += dp[i - x];
        fix(dp[i]);
    }
}

void del(int x)
{
    for(int i = x; i <= sum; i++)
    {
        dp[i] -= dp[i - x];
        fix(dp[i]);
    }
}

void solve()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i], sum += a[i];
    if(sum & 1) cout << 0, exit(0);
    
    int tmp = sum;
    sum /= 2;
    dp[0] = 1;
    for(int i = 1; i <= n; i++) 
        add(a[i]);
    if(dp[sum]== 0)
        cout << 0, exit(0);
        
    for(int i = 1; i <= n; i++)
    {
        del(a[i]);
        tmp -= a[i];
        vector<int> s;
        for(int i = 0; i <= tmp / 2; i++) if(dp[i] != 0)
        {
            int team1 = i;
            int team2 = tmp - team1;
            cnt[abs(team2 - team1)]++;
        }
        
        tmp += a[i];
        add(a[i]);
    }
    
    vector<int> res;
    for(int i = 1; i <= 500 * 500; i++)
        if(cnt[i] == n) res.pb(i);
    cout << res.size() << '\n';
    for(const int &x : res) cout << x << ' ';
}

signed main()
{
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 4 ms 340 KB Output is correct
25 Correct 5 ms 340 KB Output is correct
26 Correct 5 ms 340 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 4 ms 340 KB Output is correct
29 Correct 5 ms 392 KB Output is correct
30 Correct 4 ms 340 KB Output is correct
31 Correct 6 ms 412 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 3 ms 396 KB Output is correct
34 Correct 3 ms 340 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 4 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 4 ms 340 KB Output is correct
25 Correct 5 ms 340 KB Output is correct
26 Correct 5 ms 340 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 4 ms 340 KB Output is correct
29 Correct 5 ms 392 KB Output is correct
30 Correct 4 ms 340 KB Output is correct
31 Correct 6 ms 412 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 3 ms 396 KB Output is correct
34 Correct 3 ms 340 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 4 ms 340 KB Output is correct
37 Correct 22 ms 576 KB Output is correct
38 Correct 22 ms 576 KB Output is correct
39 Correct 29 ms 676 KB Output is correct
40 Correct 50 ms 640 KB Output is correct
41 Correct 41 ms 724 KB Output is correct
42 Correct 47 ms 624 KB Output is correct
43 Correct 75 ms 1016 KB Output is correct
44 Correct 73 ms 1024 KB Output is correct
45 Correct 77 ms 1032 KB Output is correct
46 Correct 32 ms 588 KB Output is correct
47 Correct 51 ms 664 KB Output is correct
48 Correct 77 ms 924 KB Output is correct
49 Correct 50 ms 700 KB Output is correct
50 Correct 47 ms 644 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 97 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 4 ms 340 KB Output is correct
25 Correct 5 ms 340 KB Output is correct
26 Correct 5 ms 340 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 4 ms 340 KB Output is correct
29 Correct 5 ms 392 KB Output is correct
30 Correct 4 ms 340 KB Output is correct
31 Correct 6 ms 412 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 3 ms 396 KB Output is correct
34 Correct 3 ms 340 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 4 ms 340 KB Output is correct
37 Correct 22 ms 576 KB Output is correct
38 Correct 22 ms 576 KB Output is correct
39 Correct 29 ms 676 KB Output is correct
40 Correct 50 ms 640 KB Output is correct
41 Correct 41 ms 724 KB Output is correct
42 Correct 47 ms 624 KB Output is correct
43 Correct 75 ms 1016 KB Output is correct
44 Correct 73 ms 1024 KB Output is correct
45 Correct 77 ms 1032 KB Output is correct
46 Correct 32 ms 588 KB Output is correct
47 Correct 51 ms 664 KB Output is correct
48 Correct 77 ms 924 KB Output is correct
49 Correct 50 ms 700 KB Output is correct
50 Correct 47 ms 644 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 97 ms 1108 KB Output is correct
53 Correct 86 ms 852 KB Output is correct
54 Correct 116 ms 1024 KB Output is correct
55 Correct 196 ms 1572 KB Output is correct
56 Correct 94 ms 976 KB Output is correct
57 Correct 221 ms 1580 KB Output is correct
58 Correct 134 ms 1100 KB Output is correct
59 Correct 149 ms 1244 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 165 ms 1332 KB Output is correct
62 Correct 166 ms 1412 KB Output is correct
63 Correct 182 ms 1436 KB Output is correct
64 Correct 171 ms 1416 KB Output is correct
65 Correct 35 ms 604 KB Output is correct
66 Correct 41 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 4 ms 340 KB Output is correct
25 Correct 5 ms 340 KB Output is correct
26 Correct 5 ms 340 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 4 ms 340 KB Output is correct
29 Correct 5 ms 392 KB Output is correct
30 Correct 4 ms 340 KB Output is correct
31 Correct 6 ms 412 KB Output is correct
32 Correct 3 ms 340 KB Output is correct
33 Correct 3 ms 396 KB Output is correct
34 Correct 3 ms 340 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 4 ms 340 KB Output is correct
37 Correct 22 ms 576 KB Output is correct
38 Correct 22 ms 576 KB Output is correct
39 Correct 29 ms 676 KB Output is correct
40 Correct 50 ms 640 KB Output is correct
41 Correct 41 ms 724 KB Output is correct
42 Correct 47 ms 624 KB Output is correct
43 Correct 75 ms 1016 KB Output is correct
44 Correct 73 ms 1024 KB Output is correct
45 Correct 77 ms 1032 KB Output is correct
46 Correct 32 ms 588 KB Output is correct
47 Correct 51 ms 664 KB Output is correct
48 Correct 77 ms 924 KB Output is correct
49 Correct 50 ms 700 KB Output is correct
50 Correct 47 ms 644 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 97 ms 1108 KB Output is correct
53 Correct 86 ms 852 KB Output is correct
54 Correct 116 ms 1024 KB Output is correct
55 Correct 196 ms 1572 KB Output is correct
56 Correct 94 ms 976 KB Output is correct
57 Correct 221 ms 1580 KB Output is correct
58 Correct 134 ms 1100 KB Output is correct
59 Correct 149 ms 1244 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 165 ms 1332 KB Output is correct
62 Correct 166 ms 1412 KB Output is correct
63 Correct 182 ms 1436 KB Output is correct
64 Correct 171 ms 1416 KB Output is correct
65 Correct 35 ms 604 KB Output is correct
66 Correct 41 ms 684 KB Output is correct
67 Correct 172 ms 1236 KB Output is correct
68 Correct 78 ms 468 KB Output is correct
69 Correct 579 ms 2616 KB Output is correct
70 Correct 365 ms 1732 KB Output is correct
71 Correct 347 ms 1812 KB Output is correct
72 Correct 358 ms 1048 KB Output is correct
73 Correct 339 ms 1048 KB Output is correct
74 Correct 620 ms 2800 KB Output is correct
75 Correct 488 ms 2352 KB Output is correct
76 Correct 612 ms 2896 KB Output is correct
77 Correct 674 ms 2984 KB Output is correct