Submission #791404

# Submission time Handle Problem Language Result Execution time Memory
791404 2023-07-24T06:05:28 Z t6twotwo Homework (CEOI22_homework) C++17
23 / 100
1000 ms 126024 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    int M = 0;
    vector<int> l, r, q, leaf;
    auto rec = [&](auto rec, int a, int b) -> int {
        if (a + 1 == b) {
            l.push_back(-1);
            r.push_back(-1);
            q.push_back(-1);
            leaf.push_back(M);
            return M++;
        }
        int c = 0, z = -1;
        for (int i = a; i < b; i++) {
            if (s[i] == '(') {
                c++;
            } else if (s[i] == ')') {
                c--;
            } else if (s[i] == ',') {
                if (c == 1) {
                    z = i;
                    break;
                }
            }
        }
        int u = rec(rec, a + 4, z);
        int v = rec(rec, z + 1, b - 1);
        l.push_back(u);
        r.push_back(v);
        q.push_back(s[a + 1] == 'a' ? 1 : 0);
        return M++;
    };
    rec(rec, 0, s.size());
    int N = leaf.size();
    vector<vector<int>> T(N + 1);
    vector<vector<int>> S(1 << N);
    for (int i = 0; i < (1 << N); i++) {
        T[__builtin_popcount(i)].push_back(i);
        for (int j = 0; j < N; j++) {
            if (i >> j & 1) {
                S[i].push_back(j);
            }
        }
    }
    vector<int> sz(M);
    auto dfs = [&](auto dfs, int x) -> vector<vector<bool>> {
        vector f(1 << N, vector<bool>(N));
        if (l[x] == -1) {
            sz[x] = 1;
            for (int i = 0; i < N; i++) {
                f[1 << i][i] = 1;
            }
            return f;
        };
        auto u = dfs(dfs, l[x]);
        auto v = dfs(dfs, r[x]);
        sz[x] += sz[l[x]];
        sz[x] += sz[r[x]];
        for (int a : T[sz[l[x]]]) {
            for (int i : S[a]) {
                if (!u[a][i]) {
                    continue;
                }
                for (int b : T[sz[r[x]]]) {
                    if (a & b) {
                        continue;
                    }
                    for (int j : S[b]) {
                        if (!v[b][j]) {
                            continue;
                        }
                        f[a + b][q[x] == 0 ? min(i, j) : max(i, j)] = 1;
                    }
                }
            }
        }
        return f;
    };
    auto f = dfs(dfs, M - 1);
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (f[(1 << N) - 1][i]) {
            ans++;
        }
    }
    cout << ans << "\n";
    return 6/22;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 580 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 1 ms 572 KB Output is correct
7 Correct 1 ms 580 KB Output is correct
8 Correct 1 ms 572 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 696 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 832 KB Output is correct
18 Correct 2 ms 952 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 724 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 448 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 580 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 1 ms 572 KB Output is correct
7 Correct 1 ms 580 KB Output is correct
8 Correct 1 ms 572 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 696 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 832 KB Output is correct
18 Correct 2 ms 952 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 724 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 448 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 588 ms 52184 KB Output is correct
30 Correct 511 ms 52172 KB Output is correct
31 Correct 425 ms 52180 KB Output is correct
32 Correct 295 ms 56808 KB Output is correct
33 Correct 480 ms 47552 KB Output is correct
34 Correct 260 ms 79848 KB Output is correct
35 Correct 228 ms 75208 KB Output is correct
36 Correct 182 ms 65960 KB Output is correct
37 Correct 199 ms 52184 KB Output is correct
38 Correct 246 ms 56812 KB Output is correct
39 Correct 330 ms 70656 KB Output is correct
40 Correct 274 ms 75312 KB Output is correct
41 Correct 196 ms 56780 KB Output is correct
42 Correct 175 ms 61340 KB Output is correct
43 Correct 311 ms 61364 KB Output is correct
44 Correct 174 ms 121500 KB Output is correct
45 Correct 211 ms 107576 KB Output is correct
46 Correct 160 ms 107596 KB Output is correct
47 Correct 174 ms 116976 KB Output is correct
48 Correct 183 ms 126024 KB Output is correct
49 Correct 195 ms 65936 KB Output is correct
50 Correct 224 ms 75280 KB Output is correct
51 Correct 424 ms 56772 KB Output is correct
52 Correct 570 ms 52184 KB Output is correct
53 Correct 478 ms 47568 KB Output is correct
54 Correct 237 ms 47724 KB Output is correct
55 Correct 436 ms 47568 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1037 ms 14132 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 580 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 1 ms 572 KB Output is correct
7 Correct 1 ms 580 KB Output is correct
8 Correct 1 ms 572 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 696 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 832 KB Output is correct
18 Correct 2 ms 952 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 724 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 448 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 588 ms 52184 KB Output is correct
30 Correct 511 ms 52172 KB Output is correct
31 Correct 425 ms 52180 KB Output is correct
32 Correct 295 ms 56808 KB Output is correct
33 Correct 480 ms 47552 KB Output is correct
34 Correct 260 ms 79848 KB Output is correct
35 Correct 228 ms 75208 KB Output is correct
36 Correct 182 ms 65960 KB Output is correct
37 Correct 199 ms 52184 KB Output is correct
38 Correct 246 ms 56812 KB Output is correct
39 Correct 330 ms 70656 KB Output is correct
40 Correct 274 ms 75312 KB Output is correct
41 Correct 196 ms 56780 KB Output is correct
42 Correct 175 ms 61340 KB Output is correct
43 Correct 311 ms 61364 KB Output is correct
44 Correct 174 ms 121500 KB Output is correct
45 Correct 211 ms 107576 KB Output is correct
46 Correct 160 ms 107596 KB Output is correct
47 Correct 174 ms 116976 KB Output is correct
48 Correct 183 ms 126024 KB Output is correct
49 Correct 195 ms 65936 KB Output is correct
50 Correct 224 ms 75280 KB Output is correct
51 Correct 424 ms 56772 KB Output is correct
52 Correct 570 ms 52184 KB Output is correct
53 Correct 478 ms 47568 KB Output is correct
54 Correct 237 ms 47724 KB Output is correct
55 Correct 436 ms 47568 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Runtime error 3 ms 1876 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 580 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 1 ms 572 KB Output is correct
7 Correct 1 ms 580 KB Output is correct
8 Correct 1 ms 572 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 696 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 832 KB Output is correct
18 Correct 2 ms 952 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 724 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 448 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 588 ms 52184 KB Output is correct
30 Correct 511 ms 52172 KB Output is correct
31 Correct 425 ms 52180 KB Output is correct
32 Correct 295 ms 56808 KB Output is correct
33 Correct 480 ms 47552 KB Output is correct
34 Correct 260 ms 79848 KB Output is correct
35 Correct 228 ms 75208 KB Output is correct
36 Correct 182 ms 65960 KB Output is correct
37 Correct 199 ms 52184 KB Output is correct
38 Correct 246 ms 56812 KB Output is correct
39 Correct 330 ms 70656 KB Output is correct
40 Correct 274 ms 75312 KB Output is correct
41 Correct 196 ms 56780 KB Output is correct
42 Correct 175 ms 61340 KB Output is correct
43 Correct 311 ms 61364 KB Output is correct
44 Correct 174 ms 121500 KB Output is correct
45 Correct 211 ms 107576 KB Output is correct
46 Correct 160 ms 107596 KB Output is correct
47 Correct 174 ms 116976 KB Output is correct
48 Correct 183 ms 126024 KB Output is correct
49 Correct 195 ms 65936 KB Output is correct
50 Correct 224 ms 75280 KB Output is correct
51 Correct 424 ms 56772 KB Output is correct
52 Correct 570 ms 52184 KB Output is correct
53 Correct 478 ms 47568 KB Output is correct
54 Correct 237 ms 47724 KB Output is correct
55 Correct 436 ms 47568 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Execution timed out 1037 ms 14132 KB Time limit exceeded
58 Halted 0 ms 0 KB -