Submission #700119

# Submission time Handle Problem Language Result Execution time Memory
700119 2023-02-18T16:29:35 Z fdnfksd Bootfall (IZhO17_bootfall) C++14
100 / 100
395 ms 3420 KB
#include<bits/stdc++.h>
#define task "C"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;
const int MAXN = 5e2 + 5;
const ll INF = 1e18 + 5;
const int MOD = 1e9 + 22071997;

int n;
int a[MAXN], sum = 0;

void Input()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
}

int dp[MAXN * MAXN], chk[MAXN * MAXN];


void Solve()
{
    if (sum % 2)
    {
        cout << 0;
        return;
    }
    dp[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = sum; j >= a[i]; j--)
        {
            dp[j]+=dp[j - a[i]];
            if(dp[j]>=MOD) dp[j]-=MOD;
        }
    }
    if (!dp[sum / 2])
    {
        cout << 0;
        return;
    }

    for (int i = 1; i <= n; i++)
    {
        for (int j = a[i]; j <= sum; j++)
        {
            dp[j]-= dp[j - a[i]];
            if(dp[j]<0) dp[j]+=MOD;
        }
        for (int j = 0; j <= (sum - a[i]) / 2; j++)
        {
            chk[sum - j - a[i] - j] += dp[j] > 0;
        }
        for (int j = sum; j >= a[i]; j--)
        {
            dp[j]+=dp[j - a[i]];
            if(dp[j]>=MOD) dp[j]-=MOD;
        }
    }

    vector<int> res;
    for (int i = 0; i <= sum; i++)
        if (chk[i] == n)
            res.pb(i);

    cout << res.size() << '\n';
    for (int id : res)
        cout << id << ' ';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(task".INP","r"))
    {
        freopen(task".INP","r",stdin);
        //freopen(task".OUT","w",stdout);
    }
    Input();
    Solve();
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 7 ms 340 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 4 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 4 ms 340 KB Output is correct
34 Correct 3 ms 340 KB Output is correct
35 Correct 4 ms 364 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 7 ms 340 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 4 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 4 ms 340 KB Output is correct
34 Correct 3 ms 340 KB Output is correct
35 Correct 4 ms 364 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 13 ms 608 KB Output is correct
38 Correct 13 ms 596 KB Output is correct
39 Correct 46 ms 700 KB Output is correct
40 Correct 29 ms 688 KB Output is correct
41 Correct 64 ms 888 KB Output is correct
42 Correct 24 ms 688 KB Output is correct
43 Correct 42 ms 1120 KB Output is correct
44 Correct 46 ms 1040 KB Output is correct
45 Correct 44 ms 1044 KB Output is correct
46 Correct 26 ms 468 KB Output is correct
47 Correct 32 ms 692 KB Output is correct
48 Correct 51 ms 1056 KB Output is correct
49 Correct 49 ms 788 KB Output is correct
50 Correct 27 ms 716 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 61 ms 1248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 7 ms 340 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 4 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 4 ms 340 KB Output is correct
34 Correct 3 ms 340 KB Output is correct
35 Correct 4 ms 364 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 13 ms 608 KB Output is correct
38 Correct 13 ms 596 KB Output is correct
39 Correct 46 ms 700 KB Output is correct
40 Correct 29 ms 688 KB Output is correct
41 Correct 64 ms 888 KB Output is correct
42 Correct 24 ms 688 KB Output is correct
43 Correct 42 ms 1120 KB Output is correct
44 Correct 46 ms 1040 KB Output is correct
45 Correct 44 ms 1044 KB Output is correct
46 Correct 26 ms 468 KB Output is correct
47 Correct 32 ms 692 KB Output is correct
48 Correct 51 ms 1056 KB Output is correct
49 Correct 49 ms 788 KB Output is correct
50 Correct 27 ms 716 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 61 ms 1248 KB Output is correct
53 Correct 43 ms 932 KB Output is correct
54 Correct 61 ms 1140 KB Output is correct
55 Correct 133 ms 1692 KB Output is correct
56 Correct 56 ms 1128 KB Output is correct
57 Correct 126 ms 1812 KB Output is correct
58 Correct 67 ms 1108 KB Output is correct
59 Correct 83 ms 1308 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 114 ms 1496 KB Output is correct
62 Correct 95 ms 1572 KB Output is correct
63 Correct 102 ms 1640 KB Output is correct
64 Correct 103 ms 1628 KB Output is correct
65 Correct 47 ms 684 KB Output is correct
66 Correct 63 ms 788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 7 ms 340 KB Output is correct
27 Correct 4 ms 340 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 4 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 4 ms 340 KB Output is correct
34 Correct 3 ms 340 KB Output is correct
35 Correct 4 ms 364 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 13 ms 608 KB Output is correct
38 Correct 13 ms 596 KB Output is correct
39 Correct 46 ms 700 KB Output is correct
40 Correct 29 ms 688 KB Output is correct
41 Correct 64 ms 888 KB Output is correct
42 Correct 24 ms 688 KB Output is correct
43 Correct 42 ms 1120 KB Output is correct
44 Correct 46 ms 1040 KB Output is correct
45 Correct 44 ms 1044 KB Output is correct
46 Correct 26 ms 468 KB Output is correct
47 Correct 32 ms 692 KB Output is correct
48 Correct 51 ms 1056 KB Output is correct
49 Correct 49 ms 788 KB Output is correct
50 Correct 27 ms 716 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 61 ms 1248 KB Output is correct
53 Correct 43 ms 932 KB Output is correct
54 Correct 61 ms 1140 KB Output is correct
55 Correct 133 ms 1692 KB Output is correct
56 Correct 56 ms 1128 KB Output is correct
57 Correct 126 ms 1812 KB Output is correct
58 Correct 67 ms 1108 KB Output is correct
59 Correct 83 ms 1308 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 114 ms 1496 KB Output is correct
62 Correct 95 ms 1572 KB Output is correct
63 Correct 102 ms 1640 KB Output is correct
64 Correct 103 ms 1628 KB Output is correct
65 Correct 47 ms 684 KB Output is correct
66 Correct 63 ms 788 KB Output is correct
67 Correct 104 ms 1452 KB Output is correct
68 Correct 60 ms 788 KB Output is correct
69 Correct 331 ms 3060 KB Output is correct
70 Correct 207 ms 2128 KB Output is correct
71 Correct 191 ms 2052 KB Output is correct
72 Correct 209 ms 1324 KB Output is correct
73 Correct 185 ms 1188 KB Output is correct
74 Correct 340 ms 3276 KB Output is correct
75 Correct 276 ms 2700 KB Output is correct
76 Correct 379 ms 3420 KB Output is correct
77 Correct 395 ms 3416 KB Output is correct