답안 #700128

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
700128 2023-02-18T16:37:01 Z messiuuuuu Bootfall (IZhO17_bootfall) C++14
100 / 100
415 ms 3440 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 = (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--)
        {
            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:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 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 340 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 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 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 340 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 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 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 1 ms 212 KB Output is correct
17 Correct 0 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 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 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 340 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 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 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 1 ms 212 KB Output is correct
17 Correct 0 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 1 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 4 ms 340 KB Output is correct
26 Correct 4 ms 340 KB Output is correct
27 Correct 6 ms 340 KB Output is correct
28 Correct 4 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 4 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 4 ms 408 KB Output is correct
34 Correct 4 ms 408 KB Output is correct
35 Correct 4 ms 340 KB Output is correct
36 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 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 340 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 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 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 1 ms 212 KB Output is correct
17 Correct 0 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 1 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 4 ms 340 KB Output is correct
26 Correct 4 ms 340 KB Output is correct
27 Correct 6 ms 340 KB Output is correct
28 Correct 4 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 4 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 4 ms 408 KB Output is correct
34 Correct 4 ms 408 KB Output is correct
35 Correct 4 ms 340 KB Output is correct
36 Correct 3 ms 340 KB Output is correct
37 Correct 15 ms 596 KB Output is correct
38 Correct 15 ms 596 KB Output is correct
39 Correct 51 ms 792 KB Output is correct
40 Correct 36 ms 712 KB Output is correct
41 Correct 66 ms 876 KB Output is correct
42 Correct 27 ms 716 KB Output is correct
43 Correct 52 ms 1036 KB Output is correct
44 Correct 48 ms 1044 KB Output is correct
45 Correct 49 ms 1044 KB Output is correct
46 Correct 28 ms 576 KB Output is correct
47 Correct 29 ms 724 KB Output is correct
48 Correct 54 ms 1048 KB Output is correct
49 Correct 59 ms 788 KB Output is correct
50 Correct 29 ms 724 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 65 ms 1240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 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 340 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 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 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 1 ms 212 KB Output is correct
17 Correct 0 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 1 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 4 ms 340 KB Output is correct
26 Correct 4 ms 340 KB Output is correct
27 Correct 6 ms 340 KB Output is correct
28 Correct 4 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 4 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 4 ms 408 KB Output is correct
34 Correct 4 ms 408 KB Output is correct
35 Correct 4 ms 340 KB Output is correct
36 Correct 3 ms 340 KB Output is correct
37 Correct 15 ms 596 KB Output is correct
38 Correct 15 ms 596 KB Output is correct
39 Correct 51 ms 792 KB Output is correct
40 Correct 36 ms 712 KB Output is correct
41 Correct 66 ms 876 KB Output is correct
42 Correct 27 ms 716 KB Output is correct
43 Correct 52 ms 1036 KB Output is correct
44 Correct 48 ms 1044 KB Output is correct
45 Correct 49 ms 1044 KB Output is correct
46 Correct 28 ms 576 KB Output is correct
47 Correct 29 ms 724 KB Output is correct
48 Correct 54 ms 1048 KB Output is correct
49 Correct 59 ms 788 KB Output is correct
50 Correct 29 ms 724 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 65 ms 1240 KB Output is correct
53 Correct 49 ms 920 KB Output is correct
54 Correct 75 ms 1132 KB Output is correct
55 Correct 133 ms 1744 KB Output is correct
56 Correct 58 ms 1136 KB Output is correct
57 Correct 139 ms 1868 KB Output is correct
58 Correct 76 ms 1108 KB Output is correct
59 Correct 91 ms 1296 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 109 ms 1512 KB Output is correct
62 Correct 106 ms 1576 KB Output is correct
63 Correct 114 ms 1744 KB Output is correct
64 Correct 121 ms 1628 KB Output is correct
65 Correct 50 ms 692 KB Output is correct
66 Correct 56 ms 728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 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 340 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 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 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 1 ms 212 KB Output is correct
17 Correct 0 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 1 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 4 ms 340 KB Output is correct
26 Correct 4 ms 340 KB Output is correct
27 Correct 6 ms 340 KB Output is correct
28 Correct 4 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 4 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 4 ms 408 KB Output is correct
34 Correct 4 ms 408 KB Output is correct
35 Correct 4 ms 340 KB Output is correct
36 Correct 3 ms 340 KB Output is correct
37 Correct 15 ms 596 KB Output is correct
38 Correct 15 ms 596 KB Output is correct
39 Correct 51 ms 792 KB Output is correct
40 Correct 36 ms 712 KB Output is correct
41 Correct 66 ms 876 KB Output is correct
42 Correct 27 ms 716 KB Output is correct
43 Correct 52 ms 1036 KB Output is correct
44 Correct 48 ms 1044 KB Output is correct
45 Correct 49 ms 1044 KB Output is correct
46 Correct 28 ms 576 KB Output is correct
47 Correct 29 ms 724 KB Output is correct
48 Correct 54 ms 1048 KB Output is correct
49 Correct 59 ms 788 KB Output is correct
50 Correct 29 ms 724 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 65 ms 1240 KB Output is correct
53 Correct 49 ms 920 KB Output is correct
54 Correct 75 ms 1132 KB Output is correct
55 Correct 133 ms 1744 KB Output is correct
56 Correct 58 ms 1136 KB Output is correct
57 Correct 139 ms 1868 KB Output is correct
58 Correct 76 ms 1108 KB Output is correct
59 Correct 91 ms 1296 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 109 ms 1512 KB Output is correct
62 Correct 106 ms 1576 KB Output is correct
63 Correct 114 ms 1744 KB Output is correct
64 Correct 121 ms 1628 KB Output is correct
65 Correct 50 ms 692 KB Output is correct
66 Correct 56 ms 728 KB Output is correct
67 Correct 110 ms 1360 KB Output is correct
68 Correct 65 ms 792 KB Output is correct
69 Correct 359 ms 3088 KB Output is correct
70 Correct 219 ms 2128 KB Output is correct
71 Correct 214 ms 2052 KB Output is correct
72 Correct 211 ms 1232 KB Output is correct
73 Correct 207 ms 1320 KB Output is correct
74 Correct 381 ms 3244 KB Output is correct
75 Correct 286 ms 2608 KB Output is correct
76 Correct 415 ms 3440 KB Output is correct
77 Correct 411 ms 3420 KB Output is correct