Submission #679696

# Submission time Handle Problem Language Result Execution time Memory
679696 2023-01-09T01:44:34 Z vjudge1 Bootfall (IZhO17_bootfall) C++14
65 / 100
1000 ms 3024 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 ii mod = {1e9 + 7, 1e9 + 21};

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

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

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

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

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, 1};
    for(int i = 1; i <= n; i++) 
        add(a[i]);
    if(dp[sum].F == 0 && dp[sum].S == 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].F != 0 || dp[i].S != 0)
            {
                int team1 = i;
                int team2 = tmp - team1;
                s.pb(abs(team1 - team2));
            }
        sort(all(s));
        s.resize(unique(all(s)) - s.begin());
        for(int x : s) cnt[x]++;
        
        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 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 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 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 328 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 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 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 328 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 4 ms 372 KB Output is correct
22 Correct 5 ms 380 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 8 ms 340 KB Output is correct
25 Correct 12 ms 340 KB Output is correct
26 Correct 13 ms 440 KB Output is correct
27 Correct 9 ms 340 KB Output is correct
28 Correct 9 ms 340 KB Output is correct
29 Correct 11 ms 436 KB Output is correct
30 Correct 10 ms 328 KB Output is correct
31 Correct 14 ms 328 KB Output is correct
32 Correct 10 ms 340 KB Output is correct
33 Correct 4 ms 328 KB Output is correct
34 Correct 4 ms 412 KB Output is correct
35 Correct 9 ms 340 KB Output is correct
36 Correct 10 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 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 328 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 4 ms 372 KB Output is correct
22 Correct 5 ms 380 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 8 ms 340 KB Output is correct
25 Correct 12 ms 340 KB Output is correct
26 Correct 13 ms 440 KB Output is correct
27 Correct 9 ms 340 KB Output is correct
28 Correct 9 ms 340 KB Output is correct
29 Correct 11 ms 436 KB Output is correct
30 Correct 10 ms 328 KB Output is correct
31 Correct 14 ms 328 KB Output is correct
32 Correct 10 ms 340 KB Output is correct
33 Correct 4 ms 328 KB Output is correct
34 Correct 4 ms 412 KB Output is correct
35 Correct 9 ms 340 KB Output is correct
36 Correct 10 ms 340 KB Output is correct
37 Correct 75 ms 584 KB Output is correct
38 Correct 75 ms 576 KB Output is correct
39 Correct 41 ms 724 KB Output is correct
40 Correct 166 ms 696 KB Output is correct
41 Correct 52 ms 852 KB Output is correct
42 Correct 147 ms 692 KB Output is correct
43 Correct 293 ms 1024 KB Output is correct
44 Correct 268 ms 1084 KB Output is correct
45 Correct 271 ms 1092 KB Output is correct
46 Correct 97 ms 596 KB Output is correct
47 Correct 155 ms 700 KB Output is correct
48 Correct 235 ms 1100 KB Output is correct
49 Correct 154 ms 928 KB Output is correct
50 Correct 158 ms 696 KB Output is correct
51 Correct 1 ms 328 KB Output is correct
52 Correct 336 ms 1412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 328 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 4 ms 372 KB Output is correct
22 Correct 5 ms 380 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 8 ms 340 KB Output is correct
25 Correct 12 ms 340 KB Output is correct
26 Correct 13 ms 440 KB Output is correct
27 Correct 9 ms 340 KB Output is correct
28 Correct 9 ms 340 KB Output is correct
29 Correct 11 ms 436 KB Output is correct
30 Correct 10 ms 328 KB Output is correct
31 Correct 14 ms 328 KB Output is correct
32 Correct 10 ms 340 KB Output is correct
33 Correct 4 ms 328 KB Output is correct
34 Correct 4 ms 412 KB Output is correct
35 Correct 9 ms 340 KB Output is correct
36 Correct 10 ms 340 KB Output is correct
37 Correct 75 ms 584 KB Output is correct
38 Correct 75 ms 576 KB Output is correct
39 Correct 41 ms 724 KB Output is correct
40 Correct 166 ms 696 KB Output is correct
41 Correct 52 ms 852 KB Output is correct
42 Correct 147 ms 692 KB Output is correct
43 Correct 293 ms 1024 KB Output is correct
44 Correct 268 ms 1084 KB Output is correct
45 Correct 271 ms 1092 KB Output is correct
46 Correct 97 ms 596 KB Output is correct
47 Correct 155 ms 700 KB Output is correct
48 Correct 235 ms 1100 KB Output is correct
49 Correct 154 ms 928 KB Output is correct
50 Correct 158 ms 696 KB Output is correct
51 Correct 1 ms 328 KB Output is correct
52 Correct 336 ms 1412 KB Output is correct
53 Correct 272 ms 968 KB Output is correct
54 Correct 390 ms 1180 KB Output is correct
55 Correct 738 ms 1900 KB Output is correct
56 Correct 345 ms 1280 KB Output is correct
57 Correct 830 ms 2068 KB Output is correct
58 Correct 423 ms 1220 KB Output is correct
59 Correct 551 ms 1564 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 629 ms 1676 KB Output is correct
62 Correct 610 ms 1832 KB Output is correct
63 Correct 641 ms 2004 KB Output is correct
64 Correct 625 ms 1796 KB Output is correct
65 Correct 52 ms 724 KB Output is correct
66 Correct 96 ms 792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 328 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 328 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 4 ms 372 KB Output is correct
22 Correct 5 ms 380 KB Output is correct
23 Correct 3 ms 332 KB Output is correct
24 Correct 8 ms 340 KB Output is correct
25 Correct 12 ms 340 KB Output is correct
26 Correct 13 ms 440 KB Output is correct
27 Correct 9 ms 340 KB Output is correct
28 Correct 9 ms 340 KB Output is correct
29 Correct 11 ms 436 KB Output is correct
30 Correct 10 ms 328 KB Output is correct
31 Correct 14 ms 328 KB Output is correct
32 Correct 10 ms 340 KB Output is correct
33 Correct 4 ms 328 KB Output is correct
34 Correct 4 ms 412 KB Output is correct
35 Correct 9 ms 340 KB Output is correct
36 Correct 10 ms 340 KB Output is correct
37 Correct 75 ms 584 KB Output is correct
38 Correct 75 ms 576 KB Output is correct
39 Correct 41 ms 724 KB Output is correct
40 Correct 166 ms 696 KB Output is correct
41 Correct 52 ms 852 KB Output is correct
42 Correct 147 ms 692 KB Output is correct
43 Correct 293 ms 1024 KB Output is correct
44 Correct 268 ms 1084 KB Output is correct
45 Correct 271 ms 1092 KB Output is correct
46 Correct 97 ms 596 KB Output is correct
47 Correct 155 ms 700 KB Output is correct
48 Correct 235 ms 1100 KB Output is correct
49 Correct 154 ms 928 KB Output is correct
50 Correct 158 ms 696 KB Output is correct
51 Correct 1 ms 328 KB Output is correct
52 Correct 336 ms 1412 KB Output is correct
53 Correct 272 ms 968 KB Output is correct
54 Correct 390 ms 1180 KB Output is correct
55 Correct 738 ms 1900 KB Output is correct
56 Correct 345 ms 1280 KB Output is correct
57 Correct 830 ms 2068 KB Output is correct
58 Correct 423 ms 1220 KB Output is correct
59 Correct 551 ms 1564 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 629 ms 1676 KB Output is correct
62 Correct 610 ms 1832 KB Output is correct
63 Correct 641 ms 2004 KB Output is correct
64 Correct 625 ms 1796 KB Output is correct
65 Correct 52 ms 724 KB Output is correct
66 Correct 96 ms 792 KB Output is correct
67 Correct 647 ms 1596 KB Output is correct
68 Correct 132 ms 724 KB Output is correct
69 Execution timed out 1090 ms 3024 KB Time limit exceeded
70 Halted 0 ms 0 KB -