답안 #1095038

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095038 2024-10-01T07:53:30 Z cpptowin Bootfall (IZhO17_bootfall) C++17
100 / 100
436 ms 31752 KB
#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define bitcount(x) __builtin_popcountll(x)
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
#define all(x) x.begin(), x.end()
#define ss(x) (int)x.size()
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
void add(int &x, int k)
{
    x += k;
    x %= mod;
    if(x < 0) x += mod;
}
void del(int &x, int k)
{
    x -= k;
    x %= mod;
    if(x < 0) x += mod;
}
const int nn = 250001;
int n,a[555];
bitset<nn> p[502],s[502];
main()
{
#define name "TASK"
    if (fopen(name ".inp", "r"))
    {
        freopen(name ".inp", "r", stdin);
        freopen(name ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    fo(i,1,n) cin >> a[i];
    int tot = 0;
    bitset<nn> checker;
    checker[0] = 1;
    fo(i,1,n) 
    {
        checker |= checker << a[i];
        tot += a[i];
    }
    if(tot % 2 == 1 or checker[tot / 2] == 0) return cout << 0,0;
    p[0][0] = s[n + 1][0] = 1;
    fo(i,1,n)
    {
        p[i] = p[i - 1];
        p[i] |= p[i] << a[i];
    }
    fod(i,n,1)
    {
        s[i] = s[i + 1];
        s[i] |= s[i] << a[i];
    }
    bitset<nn> odd,even,cur;
    even.set();
    odd.set();
    even[0] = 0;
    fo(i,1,n)
    {
        if(i > n / 2)
        {
            cur = p[i - 1];
            fo(j,i + 1,n) cur |= cur << a[j];
        }
        else 
        {
            cur = s[i + 1];
            fod(j,i - 1,0) cur |= cur << a[j];
        }
        int tot1 = tot - a[i];
        if(tot1 % 2 == 0)
        {
            odd &= 0;
            even &= cur >> (tot1 / 2);
        }
        else 
        {
            even &= 0;
            odd &= cur >> ((tot1 + 1) / 2);
        }
    }
    cout << even.count() + odd.count();en;
    fo(i,1,tot / 2) if(even[i]) cout << i * 2 << ' ';
    fo(i,0,(tot + 1) / 2) if(odd[i]) cout << i * 2 + 1 << ' ';
}

Compilation message

bootfall.cpp:58:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   58 | main()
      | ^~~~
bootfall.cpp: In function 'int main()':
bootfall.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen(name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 2 ms 1372 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 2 ms 1372 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 3 ms 2396 KB Output is correct
11 Correct 3 ms 2396 KB Output is correct
12 Correct 3 ms 2396 KB Output is correct
13 Correct 3 ms 2140 KB Output is correct
14 Correct 3 ms 2140 KB Output is correct
15 Correct 3 ms 2140 KB Output is correct
16 Correct 3 ms 2396 KB Output is correct
17 Correct 2 ms 1772 KB Output is correct
18 Correct 3 ms 1884 KB Output is correct
19 Correct 3 ms 2184 KB Output is correct
20 Correct 3 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 2 ms 1372 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 3 ms 2396 KB Output is correct
11 Correct 3 ms 2396 KB Output is correct
12 Correct 3 ms 2396 KB Output is correct
13 Correct 3 ms 2140 KB Output is correct
14 Correct 3 ms 2140 KB Output is correct
15 Correct 3 ms 2140 KB Output is correct
16 Correct 3 ms 2396 KB Output is correct
17 Correct 2 ms 1772 KB Output is correct
18 Correct 3 ms 1884 KB Output is correct
19 Correct 3 ms 2184 KB Output is correct
20 Correct 3 ms 2396 KB Output is correct
21 Correct 9 ms 4444 KB Output is correct
22 Correct 13 ms 4956 KB Output is correct
23 Correct 6 ms 3676 KB Output is correct
24 Correct 21 ms 6236 KB Output is correct
25 Correct 18 ms 6332 KB Output is correct
26 Correct 24 ms 6748 KB Output is correct
27 Correct 20 ms 6784 KB Output is correct
28 Correct 20 ms 6744 KB Output is correct
29 Correct 20 ms 6784 KB Output is correct
30 Correct 20 ms 6748 KB Output is correct
31 Correct 20 ms 6748 KB Output is correct
32 Correct 19 ms 6748 KB Output is correct
33 Correct 20 ms 6748 KB Output is correct
34 Correct 20 ms 6744 KB Output is correct
35 Correct 20 ms 6748 KB Output is correct
36 Correct 20 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 2 ms 1372 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 3 ms 2396 KB Output is correct
11 Correct 3 ms 2396 KB Output is correct
12 Correct 3 ms 2396 KB Output is correct
13 Correct 3 ms 2140 KB Output is correct
14 Correct 3 ms 2140 KB Output is correct
15 Correct 3 ms 2140 KB Output is correct
16 Correct 3 ms 2396 KB Output is correct
17 Correct 2 ms 1772 KB Output is correct
18 Correct 3 ms 1884 KB Output is correct
19 Correct 3 ms 2184 KB Output is correct
20 Correct 3 ms 2396 KB Output is correct
21 Correct 9 ms 4444 KB Output is correct
22 Correct 13 ms 4956 KB Output is correct
23 Correct 6 ms 3676 KB Output is correct
24 Correct 21 ms 6236 KB Output is correct
25 Correct 18 ms 6332 KB Output is correct
26 Correct 24 ms 6748 KB Output is correct
27 Correct 20 ms 6784 KB Output is correct
28 Correct 20 ms 6744 KB Output is correct
29 Correct 20 ms 6784 KB Output is correct
30 Correct 20 ms 6748 KB Output is correct
31 Correct 20 ms 6748 KB Output is correct
32 Correct 19 ms 6748 KB Output is correct
33 Correct 20 ms 6748 KB Output is correct
34 Correct 20 ms 6744 KB Output is correct
35 Correct 20 ms 6748 KB Output is correct
36 Correct 20 ms 6748 KB Output is correct
37 Correct 69 ms 12888 KB Output is correct
38 Correct 68 ms 12892 KB Output is correct
39 Correct 101 ms 15708 KB Output is correct
40 Correct 123 ms 17232 KB Output is correct
41 Correct 124 ms 16984 KB Output is correct
42 Correct 105 ms 15956 KB Output is correct
43 Correct 99 ms 15700 KB Output is correct
44 Correct 104 ms 15952 KB Output is correct
45 Correct 105 ms 15952 KB Output is correct
46 Correct 123 ms 16984 KB Output is correct
47 Correct 110 ms 15952 KB Output is correct
48 Correct 105 ms 15932 KB Output is correct
49 Correct 111 ms 15952 KB Output is correct
50 Correct 105 ms 15956 KB Output is correct
51 Correct 2 ms 604 KB Output is correct
52 Correct 120 ms 17172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 2 ms 1372 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 3 ms 2396 KB Output is correct
11 Correct 3 ms 2396 KB Output is correct
12 Correct 3 ms 2396 KB Output is correct
13 Correct 3 ms 2140 KB Output is correct
14 Correct 3 ms 2140 KB Output is correct
15 Correct 3 ms 2140 KB Output is correct
16 Correct 3 ms 2396 KB Output is correct
17 Correct 2 ms 1772 KB Output is correct
18 Correct 3 ms 1884 KB Output is correct
19 Correct 3 ms 2184 KB Output is correct
20 Correct 3 ms 2396 KB Output is correct
21 Correct 9 ms 4444 KB Output is correct
22 Correct 13 ms 4956 KB Output is correct
23 Correct 6 ms 3676 KB Output is correct
24 Correct 21 ms 6236 KB Output is correct
25 Correct 18 ms 6332 KB Output is correct
26 Correct 24 ms 6748 KB Output is correct
27 Correct 20 ms 6784 KB Output is correct
28 Correct 20 ms 6744 KB Output is correct
29 Correct 20 ms 6784 KB Output is correct
30 Correct 20 ms 6748 KB Output is correct
31 Correct 20 ms 6748 KB Output is correct
32 Correct 19 ms 6748 KB Output is correct
33 Correct 20 ms 6748 KB Output is correct
34 Correct 20 ms 6744 KB Output is correct
35 Correct 20 ms 6748 KB Output is correct
36 Correct 20 ms 6748 KB Output is correct
37 Correct 69 ms 12888 KB Output is correct
38 Correct 68 ms 12892 KB Output is correct
39 Correct 101 ms 15708 KB Output is correct
40 Correct 123 ms 17232 KB Output is correct
41 Correct 124 ms 16984 KB Output is correct
42 Correct 105 ms 15956 KB Output is correct
43 Correct 99 ms 15700 KB Output is correct
44 Correct 104 ms 15952 KB Output is correct
45 Correct 105 ms 15952 KB Output is correct
46 Correct 123 ms 16984 KB Output is correct
47 Correct 110 ms 15952 KB Output is correct
48 Correct 105 ms 15932 KB Output is correct
49 Correct 111 ms 15952 KB Output is correct
50 Correct 105 ms 15956 KB Output is correct
51 Correct 2 ms 604 KB Output is correct
52 Correct 120 ms 17172 KB Output is correct
53 Correct 149 ms 19028 KB Output is correct
54 Correct 206 ms 22048 KB Output is correct
55 Correct 198 ms 22100 KB Output is correct
56 Correct 152 ms 19360 KB Output is correct
57 Correct 236 ms 22352 KB Output is correct
58 Correct 199 ms 22056 KB Output is correct
59 Correct 202 ms 22164 KB Output is correct
60 Correct 2 ms 604 KB Output is correct
61 Correct 206 ms 22056 KB Output is correct
62 Correct 168 ms 20308 KB Output is correct
63 Correct 166 ms 20308 KB Output is correct
64 Correct 167 ms 20048 KB Output is correct
65 Correct 160 ms 19804 KB Output is correct
66 Correct 154 ms 19544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 860 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1116 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 2 ms 1372 KB Output is correct
9 Correct 1 ms 1116 KB Output is correct
10 Correct 3 ms 2396 KB Output is correct
11 Correct 3 ms 2396 KB Output is correct
12 Correct 3 ms 2396 KB Output is correct
13 Correct 3 ms 2140 KB Output is correct
14 Correct 3 ms 2140 KB Output is correct
15 Correct 3 ms 2140 KB Output is correct
16 Correct 3 ms 2396 KB Output is correct
17 Correct 2 ms 1772 KB Output is correct
18 Correct 3 ms 1884 KB Output is correct
19 Correct 3 ms 2184 KB Output is correct
20 Correct 3 ms 2396 KB Output is correct
21 Correct 9 ms 4444 KB Output is correct
22 Correct 13 ms 4956 KB Output is correct
23 Correct 6 ms 3676 KB Output is correct
24 Correct 21 ms 6236 KB Output is correct
25 Correct 18 ms 6332 KB Output is correct
26 Correct 24 ms 6748 KB Output is correct
27 Correct 20 ms 6784 KB Output is correct
28 Correct 20 ms 6744 KB Output is correct
29 Correct 20 ms 6784 KB Output is correct
30 Correct 20 ms 6748 KB Output is correct
31 Correct 20 ms 6748 KB Output is correct
32 Correct 19 ms 6748 KB Output is correct
33 Correct 20 ms 6748 KB Output is correct
34 Correct 20 ms 6744 KB Output is correct
35 Correct 20 ms 6748 KB Output is correct
36 Correct 20 ms 6748 KB Output is correct
37 Correct 69 ms 12888 KB Output is correct
38 Correct 68 ms 12892 KB Output is correct
39 Correct 101 ms 15708 KB Output is correct
40 Correct 123 ms 17232 KB Output is correct
41 Correct 124 ms 16984 KB Output is correct
42 Correct 105 ms 15956 KB Output is correct
43 Correct 99 ms 15700 KB Output is correct
44 Correct 104 ms 15952 KB Output is correct
45 Correct 105 ms 15952 KB Output is correct
46 Correct 123 ms 16984 KB Output is correct
47 Correct 110 ms 15952 KB Output is correct
48 Correct 105 ms 15932 KB Output is correct
49 Correct 111 ms 15952 KB Output is correct
50 Correct 105 ms 15956 KB Output is correct
51 Correct 2 ms 604 KB Output is correct
52 Correct 120 ms 17172 KB Output is correct
53 Correct 149 ms 19028 KB Output is correct
54 Correct 206 ms 22048 KB Output is correct
55 Correct 198 ms 22100 KB Output is correct
56 Correct 152 ms 19360 KB Output is correct
57 Correct 236 ms 22352 KB Output is correct
58 Correct 199 ms 22056 KB Output is correct
59 Correct 202 ms 22164 KB Output is correct
60 Correct 2 ms 604 KB Output is correct
61 Correct 206 ms 22056 KB Output is correct
62 Correct 168 ms 20308 KB Output is correct
63 Correct 166 ms 20308 KB Output is correct
64 Correct 167 ms 20048 KB Output is correct
65 Correct 160 ms 19804 KB Output is correct
66 Correct 154 ms 19544 KB Output is correct
67 Correct 265 ms 25108 KB Output is correct
68 Correct 5 ms 604 KB Output is correct
69 Correct 397 ms 31656 KB Output is correct
70 Correct 397 ms 31568 KB Output is correct
71 Correct 395 ms 31476 KB Output is correct
72 Correct 402 ms 31228 KB Output is correct
73 Correct 400 ms 31052 KB Output is correct
74 Correct 394 ms 31612 KB Output is correct
75 Correct 390 ms 31572 KB Output is correct
76 Correct 436 ms 31736 KB Output is correct
77 Correct 411 ms 31752 KB Output is correct