답안 #1022396

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1022396 2024-07-13T12:47:35 Z phoenix Bootfall (IZhO17_bootfall) C++17
28 / 100
1000 ms 16228 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;
const int MOD3 = 999990011;
const int MOD4 = 1e9 + 9;
 
template<unsigned int MOD> 
struct mint {
    int v;
    mint() {}
    mint(long long val) : v(val - (val >= MOD) * MOD + (val < 0) * MOD) {}
    mint<MOD>& operator += (mint<MOD> other) {
        *this = mint(v + other.v);
        return *this;
    }
    mint<MOD>& operator -= (mint<MOD> other) {
        *this = mint(v - other.v);
        return *this;
    }
};
const int N = 550;
const int A = 250000;
 
mint<MOD1> dp1[A]{1};
mint<MOD2> dp2[A]{1};
mint<MOD3> dp3[A]{1};
mint<MOD4> dp4[A]{1};
int sum = 0;
 
void add(int val) {
    sum += val;
    for (int i = A - 1; i >= val; i--) {
        dp1[i] += dp1[i - val];
        dp2[i] += dp2[i - val];
        dp3[i] += dp3[i - val];
        dp4[i] += dp4[i - val];
    }   
}
 
bool check(int sum) {
    if (sum < 0 || sum >= A) return false;

    bool flag = true;
    flag &= (dp1[sum].v > 0);
    flag &= (dp2[sum].v > 0);
    flag &= (dp3[sum].v > 0);
    flag &= (dp4[sum].v > 0);
    return flag;
}
 
void del(int val) {
    sum -= val;
    for (int i = val; i < A; i++) {
        dp1[i] -= dp1[i - val];
        dp2[i] -= dp2[i - val];
        dp3[i] -= dp3[i - val];
        dp4[i] -= dp4[i - val];
    }
}
 
int n;
int a[N];

set<int> st;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++) {
        add(a[i]);
    }
    if (sum & 1 || !check(sum / 2)) {
        cout << 0;
        return 0;
    }
    for (int i = 0; i < A; i++) st.insert(i);

    for (int i = 0; i < n; i++) {
        if (i) add(a[i - 1]);
        del(a[i]);
        if (st.empty()) {
            cout << 0;
            return 0;
        }
        int x = *st.begin();
        for (auto it = st.begin(); it != st.end(); it = st.upper_bound(x)) {
            x = *it;
            if ((x ^ sum) & 1) st.erase(it);  
            else {
                if (!check(sum - x >> 1) && !check(sum + x >> 1)) {
                    st.erase(it);
                }
            }
        }
    }
    cout << (int)st.size() << '\n';
    for (int c : st) cout << c << ' ';
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:96:32: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   96 |                 if (!check(sum - x >> 1) && !check(sum + x >> 1)) {
      |                            ~~~~^~~
bootfall.cpp:96:56: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   96 |                 if (!check(sum - x >> 1) && !check(sum + x >> 1)) {
      |                                                    ~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 15952 KB Output is correct
2 Correct 73 ms 15976 KB Output is correct
3 Correct 5 ms 4184 KB Output is correct
4 Correct 72 ms 16208 KB Output is correct
5 Correct 85 ms 15952 KB Output is correct
6 Correct 74 ms 15956 KB Output is correct
7 Correct 71 ms 15952 KB Output is correct
8 Correct 80 ms 15952 KB Output is correct
9 Correct 72 ms 16084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 15952 KB Output is correct
2 Correct 73 ms 15976 KB Output is correct
3 Correct 5 ms 4184 KB Output is correct
4 Correct 72 ms 16208 KB Output is correct
5 Correct 85 ms 15952 KB Output is correct
6 Correct 74 ms 15956 KB Output is correct
7 Correct 71 ms 15952 KB Output is correct
8 Correct 80 ms 15952 KB Output is correct
9 Correct 72 ms 16084 KB Output is correct
10 Correct 122 ms 15952 KB Output is correct
11 Correct 123 ms 15952 KB Output is correct
12 Correct 87 ms 15860 KB Output is correct
13 Correct 86 ms 16228 KB Output is correct
14 Correct 114 ms 15960 KB Output is correct
15 Correct 121 ms 15956 KB Output is correct
16 Correct 120 ms 15940 KB Output is correct
17 Correct 114 ms 15952 KB Output is correct
18 Correct 110 ms 15960 KB Output is correct
19 Correct 113 ms 15952 KB Output is correct
20 Correct 122 ms 15952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 15952 KB Output is correct
2 Correct 73 ms 15976 KB Output is correct
3 Correct 5 ms 4184 KB Output is correct
4 Correct 72 ms 16208 KB Output is correct
5 Correct 85 ms 15952 KB Output is correct
6 Correct 74 ms 15956 KB Output is correct
7 Correct 71 ms 15952 KB Output is correct
8 Correct 80 ms 15952 KB Output is correct
9 Correct 72 ms 16084 KB Output is correct
10 Correct 122 ms 15952 KB Output is correct
11 Correct 123 ms 15952 KB Output is correct
12 Correct 87 ms 15860 KB Output is correct
13 Correct 86 ms 16228 KB Output is correct
14 Correct 114 ms 15960 KB Output is correct
15 Correct 121 ms 15956 KB Output is correct
16 Correct 120 ms 15940 KB Output is correct
17 Correct 114 ms 15952 KB Output is correct
18 Correct 110 ms 15960 KB Output is correct
19 Correct 113 ms 15952 KB Output is correct
20 Correct 122 ms 15952 KB Output is correct
21 Correct 213 ms 16208 KB Output is correct
22 Correct 222 ms 15864 KB Output is correct
23 Correct 165 ms 15952 KB Output is correct
24 Correct 273 ms 15952 KB Output is correct
25 Correct 283 ms 15876 KB Output is correct
26 Correct 285 ms 15876 KB Output is correct
27 Correct 303 ms 15860 KB Output is correct
28 Correct 311 ms 15956 KB Output is correct
29 Correct 275 ms 15952 KB Output is correct
30 Correct 154 ms 15880 KB Output is correct
31 Correct 297 ms 16116 KB Output is correct
32 Correct 290 ms 15952 KB Output is correct
33 Correct 272 ms 15952 KB Output is correct
34 Correct 264 ms 15952 KB Output is correct
35 Correct 270 ms 16088 KB Output is correct
36 Correct 290 ms 15864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 15952 KB Output is correct
2 Correct 73 ms 15976 KB Output is correct
3 Correct 5 ms 4184 KB Output is correct
4 Correct 72 ms 16208 KB Output is correct
5 Correct 85 ms 15952 KB Output is correct
6 Correct 74 ms 15956 KB Output is correct
7 Correct 71 ms 15952 KB Output is correct
8 Correct 80 ms 15952 KB Output is correct
9 Correct 72 ms 16084 KB Output is correct
10 Correct 122 ms 15952 KB Output is correct
11 Correct 123 ms 15952 KB Output is correct
12 Correct 87 ms 15860 KB Output is correct
13 Correct 86 ms 16228 KB Output is correct
14 Correct 114 ms 15960 KB Output is correct
15 Correct 121 ms 15956 KB Output is correct
16 Correct 120 ms 15940 KB Output is correct
17 Correct 114 ms 15952 KB Output is correct
18 Correct 110 ms 15960 KB Output is correct
19 Correct 113 ms 15952 KB Output is correct
20 Correct 122 ms 15952 KB Output is correct
21 Correct 213 ms 16208 KB Output is correct
22 Correct 222 ms 15864 KB Output is correct
23 Correct 165 ms 15952 KB Output is correct
24 Correct 273 ms 15952 KB Output is correct
25 Correct 283 ms 15876 KB Output is correct
26 Correct 285 ms 15876 KB Output is correct
27 Correct 303 ms 15860 KB Output is correct
28 Correct 311 ms 15956 KB Output is correct
29 Correct 275 ms 15952 KB Output is correct
30 Correct 154 ms 15880 KB Output is correct
31 Correct 297 ms 16116 KB Output is correct
32 Correct 290 ms 15952 KB Output is correct
33 Correct 272 ms 15952 KB Output is correct
34 Correct 264 ms 15952 KB Output is correct
35 Correct 270 ms 16088 KB Output is correct
36 Correct 290 ms 15864 KB Output is correct
37 Correct 630 ms 16140 KB Output is correct
38 Correct 651 ms 16136 KB Output is correct
39 Correct 581 ms 15872 KB Output is correct
40 Correct 999 ms 16088 KB Output is correct
41 Correct 634 ms 15880 KB Output is correct
42 Correct 909 ms 16088 KB Output is correct
43 Execution timed out 1072 ms 15868 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 15952 KB Output is correct
2 Correct 73 ms 15976 KB Output is correct
3 Correct 5 ms 4184 KB Output is correct
4 Correct 72 ms 16208 KB Output is correct
5 Correct 85 ms 15952 KB Output is correct
6 Correct 74 ms 15956 KB Output is correct
7 Correct 71 ms 15952 KB Output is correct
8 Correct 80 ms 15952 KB Output is correct
9 Correct 72 ms 16084 KB Output is correct
10 Correct 122 ms 15952 KB Output is correct
11 Correct 123 ms 15952 KB Output is correct
12 Correct 87 ms 15860 KB Output is correct
13 Correct 86 ms 16228 KB Output is correct
14 Correct 114 ms 15960 KB Output is correct
15 Correct 121 ms 15956 KB Output is correct
16 Correct 120 ms 15940 KB Output is correct
17 Correct 114 ms 15952 KB Output is correct
18 Correct 110 ms 15960 KB Output is correct
19 Correct 113 ms 15952 KB Output is correct
20 Correct 122 ms 15952 KB Output is correct
21 Correct 213 ms 16208 KB Output is correct
22 Correct 222 ms 15864 KB Output is correct
23 Correct 165 ms 15952 KB Output is correct
24 Correct 273 ms 15952 KB Output is correct
25 Correct 283 ms 15876 KB Output is correct
26 Correct 285 ms 15876 KB Output is correct
27 Correct 303 ms 15860 KB Output is correct
28 Correct 311 ms 15956 KB Output is correct
29 Correct 275 ms 15952 KB Output is correct
30 Correct 154 ms 15880 KB Output is correct
31 Correct 297 ms 16116 KB Output is correct
32 Correct 290 ms 15952 KB Output is correct
33 Correct 272 ms 15952 KB Output is correct
34 Correct 264 ms 15952 KB Output is correct
35 Correct 270 ms 16088 KB Output is correct
36 Correct 290 ms 15864 KB Output is correct
37 Correct 630 ms 16140 KB Output is correct
38 Correct 651 ms 16136 KB Output is correct
39 Correct 581 ms 15872 KB Output is correct
40 Correct 999 ms 16088 KB Output is correct
41 Correct 634 ms 15880 KB Output is correct
42 Correct 909 ms 16088 KB Output is correct
43 Execution timed out 1072 ms 15868 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 15952 KB Output is correct
2 Correct 73 ms 15976 KB Output is correct
3 Correct 5 ms 4184 KB Output is correct
4 Correct 72 ms 16208 KB Output is correct
5 Correct 85 ms 15952 KB Output is correct
6 Correct 74 ms 15956 KB Output is correct
7 Correct 71 ms 15952 KB Output is correct
8 Correct 80 ms 15952 KB Output is correct
9 Correct 72 ms 16084 KB Output is correct
10 Correct 122 ms 15952 KB Output is correct
11 Correct 123 ms 15952 KB Output is correct
12 Correct 87 ms 15860 KB Output is correct
13 Correct 86 ms 16228 KB Output is correct
14 Correct 114 ms 15960 KB Output is correct
15 Correct 121 ms 15956 KB Output is correct
16 Correct 120 ms 15940 KB Output is correct
17 Correct 114 ms 15952 KB Output is correct
18 Correct 110 ms 15960 KB Output is correct
19 Correct 113 ms 15952 KB Output is correct
20 Correct 122 ms 15952 KB Output is correct
21 Correct 213 ms 16208 KB Output is correct
22 Correct 222 ms 15864 KB Output is correct
23 Correct 165 ms 15952 KB Output is correct
24 Correct 273 ms 15952 KB Output is correct
25 Correct 283 ms 15876 KB Output is correct
26 Correct 285 ms 15876 KB Output is correct
27 Correct 303 ms 15860 KB Output is correct
28 Correct 311 ms 15956 KB Output is correct
29 Correct 275 ms 15952 KB Output is correct
30 Correct 154 ms 15880 KB Output is correct
31 Correct 297 ms 16116 KB Output is correct
32 Correct 290 ms 15952 KB Output is correct
33 Correct 272 ms 15952 KB Output is correct
34 Correct 264 ms 15952 KB Output is correct
35 Correct 270 ms 16088 KB Output is correct
36 Correct 290 ms 15864 KB Output is correct
37 Correct 630 ms 16140 KB Output is correct
38 Correct 651 ms 16136 KB Output is correct
39 Correct 581 ms 15872 KB Output is correct
40 Correct 999 ms 16088 KB Output is correct
41 Correct 634 ms 15880 KB Output is correct
42 Correct 909 ms 16088 KB Output is correct
43 Execution timed out 1072 ms 15868 KB Time limit exceeded
44 Halted 0 ms 0 KB -