Submission #700121

# Submission time Handle Problem Language Result Execution time Memory
700121 2023-02-18T16:32:30 Z messiuuuuu Bootfall (IZhO17_bootfall) C++14
65 / 100
1000 ms 3060 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];
 
inline void add(int& a, int b)
{
    a += b;
    if (a >= MOD)
        a -= MOD;
    if (a < 0)
        a += MOD;
}
 
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--)
        {
            add(dp[j], dp[j - a[i]]);
        }
    }
    if (!dp[sum / 2])
    {
        cout << 0;
        return;
    }
 
    for (int i = 1; i <= n; i++)
    {
        for (int j = a[i]; j <= sum; j++)
        {
            add(dp[j], -dp[j - a[i]]);
        }
        for (int j = (sum - a[i]) & 1; j <= sum; j += 2)
        {
            chk[j] += dp[(sum + j - a[i]) / 2] > 0;
        }
        for (int j = sum; j >= a[i]; j--)
        {
            add(dp[j], dp[j - a[i]]);
        }
    }
 
    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:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |         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 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 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 0 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 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 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 0 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 1 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 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 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 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 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 0 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 1 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 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 3 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 4 ms 360 KB Output is correct
25 Correct 6 ms 404 KB Output is correct
26 Correct 7 ms 340 KB Output is correct
27 Correct 5 ms 340 KB Output is correct
28 Correct 5 ms 340 KB Output is correct
29 Correct 5 ms 340 KB Output is correct
30 Correct 5 ms 340 KB Output is correct
31 Correct 7 ms 384 KB Output is correct
32 Correct 4 ms 340 KB Output is correct
33 Correct 5 ms 404 KB Output is correct
34 Correct 4 ms 340 KB Output is correct
35 Correct 7 ms 468 KB Output is correct
36 Correct 5 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 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 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 0 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 1 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 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 3 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 4 ms 360 KB Output is correct
25 Correct 6 ms 404 KB Output is correct
26 Correct 7 ms 340 KB Output is correct
27 Correct 5 ms 340 KB Output is correct
28 Correct 5 ms 340 KB Output is correct
29 Correct 5 ms 340 KB Output is correct
30 Correct 5 ms 340 KB Output is correct
31 Correct 7 ms 384 KB Output is correct
32 Correct 4 ms 340 KB Output is correct
33 Correct 5 ms 404 KB Output is correct
34 Correct 4 ms 340 KB Output is correct
35 Correct 7 ms 468 KB Output is correct
36 Correct 5 ms 340 KB Output is correct
37 Correct 38 ms 528 KB Output is correct
38 Correct 43 ms 592 KB Output is correct
39 Correct 59 ms 724 KB Output is correct
40 Correct 81 ms 696 KB Output is correct
41 Correct 69 ms 880 KB Output is correct
42 Correct 77 ms 704 KB Output is correct
43 Correct 131 ms 1036 KB Output is correct
44 Correct 129 ms 1056 KB Output is correct
45 Correct 127 ms 1052 KB Output is correct
46 Correct 56 ms 564 KB Output is correct
47 Correct 76 ms 696 KB Output is correct
48 Correct 122 ms 1048 KB Output is correct
49 Correct 89 ms 820 KB Output is correct
50 Correct 75 ms 724 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 178 ms 1244 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 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 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 0 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 1 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 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 3 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 4 ms 360 KB Output is correct
25 Correct 6 ms 404 KB Output is correct
26 Correct 7 ms 340 KB Output is correct
27 Correct 5 ms 340 KB Output is correct
28 Correct 5 ms 340 KB Output is correct
29 Correct 5 ms 340 KB Output is correct
30 Correct 5 ms 340 KB Output is correct
31 Correct 7 ms 384 KB Output is correct
32 Correct 4 ms 340 KB Output is correct
33 Correct 5 ms 404 KB Output is correct
34 Correct 4 ms 340 KB Output is correct
35 Correct 7 ms 468 KB Output is correct
36 Correct 5 ms 340 KB Output is correct
37 Correct 38 ms 528 KB Output is correct
38 Correct 43 ms 592 KB Output is correct
39 Correct 59 ms 724 KB Output is correct
40 Correct 81 ms 696 KB Output is correct
41 Correct 69 ms 880 KB Output is correct
42 Correct 77 ms 704 KB Output is correct
43 Correct 131 ms 1036 KB Output is correct
44 Correct 129 ms 1056 KB Output is correct
45 Correct 127 ms 1052 KB Output is correct
46 Correct 56 ms 564 KB Output is correct
47 Correct 76 ms 696 KB Output is correct
48 Correct 122 ms 1048 KB Output is correct
49 Correct 89 ms 820 KB Output is correct
50 Correct 75 ms 724 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 178 ms 1244 KB Output is correct
53 Correct 126 ms 992 KB Output is correct
54 Correct 195 ms 1124 KB Output is correct
55 Correct 336 ms 1784 KB Output is correct
56 Correct 158 ms 1128 KB Output is correct
57 Correct 359 ms 1864 KB Output is correct
58 Correct 202 ms 1200 KB Output is correct
59 Correct 254 ms 1388 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 290 ms 1548 KB Output is correct
62 Correct 281 ms 1568 KB Output is correct
63 Correct 305 ms 1616 KB Output is correct
64 Correct 309 ms 1628 KB Output is correct
65 Correct 56 ms 640 KB Output is correct
66 Correct 77 ms 724 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 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 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 0 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 1 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 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 3 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 4 ms 360 KB Output is correct
25 Correct 6 ms 404 KB Output is correct
26 Correct 7 ms 340 KB Output is correct
27 Correct 5 ms 340 KB Output is correct
28 Correct 5 ms 340 KB Output is correct
29 Correct 5 ms 340 KB Output is correct
30 Correct 5 ms 340 KB Output is correct
31 Correct 7 ms 384 KB Output is correct
32 Correct 4 ms 340 KB Output is correct
33 Correct 5 ms 404 KB Output is correct
34 Correct 4 ms 340 KB Output is correct
35 Correct 7 ms 468 KB Output is correct
36 Correct 5 ms 340 KB Output is correct
37 Correct 38 ms 528 KB Output is correct
38 Correct 43 ms 592 KB Output is correct
39 Correct 59 ms 724 KB Output is correct
40 Correct 81 ms 696 KB Output is correct
41 Correct 69 ms 880 KB Output is correct
42 Correct 77 ms 704 KB Output is correct
43 Correct 131 ms 1036 KB Output is correct
44 Correct 129 ms 1056 KB Output is correct
45 Correct 127 ms 1052 KB Output is correct
46 Correct 56 ms 564 KB Output is correct
47 Correct 76 ms 696 KB Output is correct
48 Correct 122 ms 1048 KB Output is correct
49 Correct 89 ms 820 KB Output is correct
50 Correct 75 ms 724 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 178 ms 1244 KB Output is correct
53 Correct 126 ms 992 KB Output is correct
54 Correct 195 ms 1124 KB Output is correct
55 Correct 336 ms 1784 KB Output is correct
56 Correct 158 ms 1128 KB Output is correct
57 Correct 359 ms 1864 KB Output is correct
58 Correct 202 ms 1200 KB Output is correct
59 Correct 254 ms 1388 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 290 ms 1548 KB Output is correct
62 Correct 281 ms 1568 KB Output is correct
63 Correct 305 ms 1616 KB Output is correct
64 Correct 309 ms 1628 KB Output is correct
65 Correct 56 ms 640 KB Output is correct
66 Correct 77 ms 724 KB Output is correct
67 Correct 278 ms 1452 KB Output is correct
68 Correct 124 ms 788 KB Output is correct
69 Correct 993 ms 3060 KB Output is correct
70 Correct 633 ms 2084 KB Output is correct
71 Correct 628 ms 2048 KB Output is correct
72 Correct 664 ms 1304 KB Output is correct
73 Correct 631 ms 1356 KB Output is correct
74 Execution timed out 1074 ms 2084 KB Time limit exceeded
75 Halted 0 ms 0 KB -