Submission #530740

# Submission time Handle Problem Language Result Execution time Memory
530740 2022-02-26T15:44:24 Z Killer2501 Bootfall (IZhO17_bootfall) C++14
100 / 100
295 ms 3856 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 5e2+5;
const int M = 250;
const int mod = 1e9+7;
const ll base = 75;
const int inf = 1e9;
int n, t, b[N*N], d[N], lab[N], c[N], a[N];
int ans, tong;
ll dp[N*N];
ll m, k;
pii p[N], start, finish;
vector<int> gx[N], gy[N];
vector<pii> vi;
string s[N];
void sol()
{
    cin >> n;
    dp[0] = 1;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        for(int j = tong; j >= 0; j --)dp[j+a[i]] += dp[j];
        tong += a[i];
    }
    if((tong&1) || dp[tong>>1]==0)
    {
        cout << 0;
        return;
    }
    for(int i = 1; i <= n; i ++)
    {
        for(int j = a[i]; j <= tong; j ++)dp[j] -= dp[j-a[i]];
        tong -= a[i];
        for(int j = (tong&1); j <= tong; j += 2)
            if(dp[(tong+j)>>1])++b[j];
        for(int j = tong; j >= 0; j --)dp[j+a[i]] += dp[j];
        tong += a[i];
    }
    for(int i = 0; i < N*N; i ++)if(b[i] == n)++ans;
    cout << ans << '\n';
    for(int i = 0; i < N*N; i ++)if(b[i] == n)cout << i <<" ";
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    #define task "test"
    if(fopen(task".inp", "r"))
	{
		freopen(task".inp", "r", stdin);
		freopen(task".out", "w", stdout);
	}
    int test = 1;
    //cin >> test;
    while(test -- > 0)sol();
    return 0;
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:60:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:61:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 2 ms 360 KB Output is correct
14 Correct 1 ms 368 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 2 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 2 ms 360 KB Output is correct
14 Correct 1 ms 368 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 2 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 3 ms 364 KB Output is correct
25 Correct 3 ms 464 KB Output is correct
26 Correct 3 ms 464 KB Output is correct
27 Correct 4 ms 464 KB Output is correct
28 Correct 3 ms 480 KB Output is correct
29 Correct 3 ms 492 KB Output is correct
30 Correct 3 ms 336 KB Output is correct
31 Correct 3 ms 464 KB Output is correct
32 Correct 4 ms 432 KB Output is correct
33 Correct 4 ms 464 KB Output is correct
34 Correct 3 ms 464 KB Output is correct
35 Correct 3 ms 464 KB Output is correct
36 Correct 2 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 2 ms 360 KB Output is correct
14 Correct 1 ms 368 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 2 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 3 ms 364 KB Output is correct
25 Correct 3 ms 464 KB Output is correct
26 Correct 3 ms 464 KB Output is correct
27 Correct 4 ms 464 KB Output is correct
28 Correct 3 ms 480 KB Output is correct
29 Correct 3 ms 492 KB Output is correct
30 Correct 3 ms 336 KB Output is correct
31 Correct 3 ms 464 KB Output is correct
32 Correct 4 ms 432 KB Output is correct
33 Correct 4 ms 464 KB Output is correct
34 Correct 3 ms 464 KB Output is correct
35 Correct 3 ms 464 KB Output is correct
36 Correct 2 ms 336 KB Output is correct
37 Correct 10 ms 592 KB Output is correct
38 Correct 13 ms 592 KB Output is correct
39 Correct 31 ms 1076 KB Output is correct
40 Correct 23 ms 728 KB Output is correct
41 Correct 45 ms 1168 KB Output is correct
42 Correct 22 ms 720 KB Output is correct
43 Correct 31 ms 1136 KB Output is correct
44 Correct 31 ms 1156 KB Output is correct
45 Correct 32 ms 1160 KB Output is correct
46 Correct 18 ms 720 KB Output is correct
47 Correct 24 ms 752 KB Output is correct
48 Correct 51 ms 1092 KB Output is correct
49 Correct 54 ms 1080 KB Output is correct
50 Correct 18 ms 848 KB Output is correct
51 Correct 3 ms 592 KB Output is correct
52 Correct 41 ms 1312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 2 ms 360 KB Output is correct
14 Correct 1 ms 368 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 2 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 3 ms 364 KB Output is correct
25 Correct 3 ms 464 KB Output is correct
26 Correct 3 ms 464 KB Output is correct
27 Correct 4 ms 464 KB Output is correct
28 Correct 3 ms 480 KB Output is correct
29 Correct 3 ms 492 KB Output is correct
30 Correct 3 ms 336 KB Output is correct
31 Correct 3 ms 464 KB Output is correct
32 Correct 4 ms 432 KB Output is correct
33 Correct 4 ms 464 KB Output is correct
34 Correct 3 ms 464 KB Output is correct
35 Correct 3 ms 464 KB Output is correct
36 Correct 2 ms 336 KB Output is correct
37 Correct 10 ms 592 KB Output is correct
38 Correct 13 ms 592 KB Output is correct
39 Correct 31 ms 1076 KB Output is correct
40 Correct 23 ms 728 KB Output is correct
41 Correct 45 ms 1168 KB Output is correct
42 Correct 22 ms 720 KB Output is correct
43 Correct 31 ms 1136 KB Output is correct
44 Correct 31 ms 1156 KB Output is correct
45 Correct 32 ms 1160 KB Output is correct
46 Correct 18 ms 720 KB Output is correct
47 Correct 24 ms 752 KB Output is correct
48 Correct 51 ms 1092 KB Output is correct
49 Correct 54 ms 1080 KB Output is correct
50 Correct 18 ms 848 KB Output is correct
51 Correct 3 ms 592 KB Output is correct
52 Correct 41 ms 1312 KB Output is correct
53 Correct 31 ms 972 KB Output is correct
54 Correct 43 ms 1136 KB Output is correct
55 Correct 92 ms 1904 KB Output is correct
56 Correct 42 ms 1152 KB Output is correct
57 Correct 94 ms 1984 KB Output is correct
58 Correct 47 ms 1220 KB Output is correct
59 Correct 62 ms 1348 KB Output is correct
60 Correct 8 ms 848 KB Output is correct
61 Correct 70 ms 1484 KB Output is correct
62 Correct 71 ms 1740 KB Output is correct
63 Correct 72 ms 1864 KB Output is correct
64 Correct 70 ms 1812 KB Output is correct
65 Correct 43 ms 936 KB Output is correct
66 Correct 46 ms 976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 2 ms 360 KB Output is correct
14 Correct 1 ms 368 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 2 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 3 ms 364 KB Output is correct
25 Correct 3 ms 464 KB Output is correct
26 Correct 3 ms 464 KB Output is correct
27 Correct 4 ms 464 KB Output is correct
28 Correct 3 ms 480 KB Output is correct
29 Correct 3 ms 492 KB Output is correct
30 Correct 3 ms 336 KB Output is correct
31 Correct 3 ms 464 KB Output is correct
32 Correct 4 ms 432 KB Output is correct
33 Correct 4 ms 464 KB Output is correct
34 Correct 3 ms 464 KB Output is correct
35 Correct 3 ms 464 KB Output is correct
36 Correct 2 ms 336 KB Output is correct
37 Correct 10 ms 592 KB Output is correct
38 Correct 13 ms 592 KB Output is correct
39 Correct 31 ms 1076 KB Output is correct
40 Correct 23 ms 728 KB Output is correct
41 Correct 45 ms 1168 KB Output is correct
42 Correct 22 ms 720 KB Output is correct
43 Correct 31 ms 1136 KB Output is correct
44 Correct 31 ms 1156 KB Output is correct
45 Correct 32 ms 1160 KB Output is correct
46 Correct 18 ms 720 KB Output is correct
47 Correct 24 ms 752 KB Output is correct
48 Correct 51 ms 1092 KB Output is correct
49 Correct 54 ms 1080 KB Output is correct
50 Correct 18 ms 848 KB Output is correct
51 Correct 3 ms 592 KB Output is correct
52 Correct 41 ms 1312 KB Output is correct
53 Correct 31 ms 972 KB Output is correct
54 Correct 43 ms 1136 KB Output is correct
55 Correct 92 ms 1904 KB Output is correct
56 Correct 42 ms 1152 KB Output is correct
57 Correct 94 ms 1984 KB Output is correct
58 Correct 47 ms 1220 KB Output is correct
59 Correct 62 ms 1348 KB Output is correct
60 Correct 8 ms 848 KB Output is correct
61 Correct 70 ms 1484 KB Output is correct
62 Correct 71 ms 1740 KB Output is correct
63 Correct 72 ms 1864 KB Output is correct
64 Correct 70 ms 1812 KB Output is correct
65 Correct 43 ms 936 KB Output is correct
66 Correct 46 ms 976 KB Output is correct
67 Correct 65 ms 1424 KB Output is correct
68 Correct 18 ms 1344 KB Output is correct
69 Correct 233 ms 3472 KB Output is correct
70 Correct 156 ms 2244 KB Output is correct
71 Correct 138 ms 2116 KB Output is correct
72 Correct 147 ms 1824 KB Output is correct
73 Correct 137 ms 1772 KB Output is correct
74 Correct 259 ms 3620 KB Output is correct
75 Correct 195 ms 2848 KB Output is correct
76 Correct 295 ms 3856 KB Output is correct
77 Correct 289 ms 3772 KB Output is correct