Submission #791431

# Submission time Handle Problem Language Result Execution time Memory
791431 2023-07-24T06:26:53 Z t6twotwo Homework (CEOI22_homework) C++17
36 / 100
570 ms 126068 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, N = 0;
    vector<int> l, r, q, stk, t(s.size());
    for (int i = 0; i < s.size(); i++) {
        if (isalpha(s[i])) {
            continue;
        }
        if (s[i] == '?') {
            l.push_back(-1);
            r.push_back(-1);
            q.push_back(-1);
            N++;
            t[i] = M++;
        } else if (s[i] == '(') {
            stk.push_back(i);
        } else if (s[i] == ',') {
            int j = stk.back();
            t[j] = t[i - 1];
        } else if (s[i] == ')') {
            int j = stk.back();
            stk.pop_back();
            l.push_back(t[j]);
            r.push_back(t[i - 1]);
            q.push_back(s[j - 1] == 'x' ? 1 : 0);
            t[i] = M++;
        }
    }
    if (N <= 16) {
        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 0;
    }
    vector<int> a;
    int x = M - 1;
    while (1) {
        a.push_back(q[x]);
        if (l[l[x]] != -1) {
            x = l[x];
        } else if (l[r[x]] != -1) {
            x = r[x];
        } else {
            break;
        }
    }
    for (int i = 1; i < N - 1; i++) {
        if (a[i] != a[i - 1]) {
            cout << N - i << "\n";
            return 0;
        }
    }
    cout << 1 << "\n";
    return 6/22;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:11:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for (int i = 0; i < s.size(); i++) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 580 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 596 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 724 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 2 ms 852 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 700 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 580 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 468 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 580 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 596 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 724 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 2 ms 852 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 700 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 580 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 468 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 522 ms 52192 KB Output is correct
30 Correct 515 ms 52196 KB Output is correct
31 Correct 427 ms 52304 KB Output is correct
32 Correct 306 ms 56808 KB Output is correct
33 Correct 479 ms 47688 KB Output is correct
34 Correct 254 ms 79888 KB Output is correct
35 Correct 242 ms 75340 KB Output is correct
36 Correct 184 ms 65956 KB Output is correct
37 Correct 180 ms 52100 KB Output is correct
38 Correct 250 ms 56816 KB Output is correct
39 Correct 333 ms 70568 KB Output is correct
40 Correct 276 ms 75304 KB Output is correct
41 Correct 191 ms 56716 KB Output is correct
42 Correct 181 ms 61428 KB Output is correct
43 Correct 327 ms 61384 KB Output is correct
44 Correct 187 ms 121424 KB Output is correct
45 Correct 185 ms 107660 KB Output is correct
46 Correct 165 ms 107664 KB Output is correct
47 Correct 190 ms 116840 KB Output is correct
48 Correct 182 ms 126068 KB Output is correct
49 Correct 175 ms 65964 KB Output is correct
50 Correct 218 ms 75256 KB Output is correct
51 Correct 417 ms 56784 KB Output is correct
52 Correct 570 ms 52188 KB Output is correct
53 Correct 461 ms 47568 KB Output is correct
54 Correct 225 ms 47660 KB Output is correct
55 Correct 404 ms 47500 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 70760 KB Output is correct
2 Correct 94 ms 72284 KB Output is correct
3 Correct 93 ms 72384 KB Output is correct
4 Correct 98 ms 72384 KB Output is correct
5 Correct 91 ms 72244 KB Output is correct
6 Correct 90 ms 72256 KB Output is correct
7 Correct 91 ms 72236 KB Output is correct
8 Correct 90 ms 72492 KB Output is correct
9 Correct 87 ms 72188 KB Output is correct
10 Correct 85 ms 72220 KB Output is correct
11 Correct 88 ms 72200 KB Output is correct
12 Correct 86 ms 72268 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 580 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 596 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 724 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 2 ms 852 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 700 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 580 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 468 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 522 ms 52192 KB Output is correct
30 Correct 515 ms 52196 KB Output is correct
31 Correct 427 ms 52304 KB Output is correct
32 Correct 306 ms 56808 KB Output is correct
33 Correct 479 ms 47688 KB Output is correct
34 Correct 254 ms 79888 KB Output is correct
35 Correct 242 ms 75340 KB Output is correct
36 Correct 184 ms 65956 KB Output is correct
37 Correct 180 ms 52100 KB Output is correct
38 Correct 250 ms 56816 KB Output is correct
39 Correct 333 ms 70568 KB Output is correct
40 Correct 276 ms 75304 KB Output is correct
41 Correct 191 ms 56716 KB Output is correct
42 Correct 181 ms 61428 KB Output is correct
43 Correct 327 ms 61384 KB Output is correct
44 Correct 187 ms 121424 KB Output is correct
45 Correct 185 ms 107660 KB Output is correct
46 Correct 165 ms 107664 KB Output is correct
47 Correct 190 ms 116840 KB Output is correct
48 Correct 182 ms 126068 KB Output is correct
49 Correct 175 ms 65964 KB Output is correct
50 Correct 218 ms 75256 KB Output is correct
51 Correct 417 ms 56784 KB Output is correct
52 Correct 570 ms 52188 KB Output is correct
53 Correct 461 ms 47568 KB Output is correct
54 Correct 225 ms 47660 KB Output is correct
55 Correct 404 ms 47500 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Incorrect 1 ms 340 KB Output isn't correct
58 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 580 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 596 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 724 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 2 ms 852 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 700 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 580 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 468 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 522 ms 52192 KB Output is correct
30 Correct 515 ms 52196 KB Output is correct
31 Correct 427 ms 52304 KB Output is correct
32 Correct 306 ms 56808 KB Output is correct
33 Correct 479 ms 47688 KB Output is correct
34 Correct 254 ms 79888 KB Output is correct
35 Correct 242 ms 75340 KB Output is correct
36 Correct 184 ms 65956 KB Output is correct
37 Correct 180 ms 52100 KB Output is correct
38 Correct 250 ms 56816 KB Output is correct
39 Correct 333 ms 70568 KB Output is correct
40 Correct 276 ms 75304 KB Output is correct
41 Correct 191 ms 56716 KB Output is correct
42 Correct 181 ms 61428 KB Output is correct
43 Correct 327 ms 61384 KB Output is correct
44 Correct 187 ms 121424 KB Output is correct
45 Correct 185 ms 107660 KB Output is correct
46 Correct 165 ms 107664 KB Output is correct
47 Correct 190 ms 116840 KB Output is correct
48 Correct 182 ms 126068 KB Output is correct
49 Correct 175 ms 65964 KB Output is correct
50 Correct 218 ms 75256 KB Output is correct
51 Correct 417 ms 56784 KB Output is correct
52 Correct 570 ms 52188 KB Output is correct
53 Correct 461 ms 47568 KB Output is correct
54 Correct 225 ms 47660 KB Output is correct
55 Correct 404 ms 47500 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 84 ms 70760 KB Output is correct
58 Correct 94 ms 72284 KB Output is correct
59 Correct 93 ms 72384 KB Output is correct
60 Correct 98 ms 72384 KB Output is correct
61 Correct 91 ms 72244 KB Output is correct
62 Correct 90 ms 72256 KB Output is correct
63 Correct 91 ms 72236 KB Output is correct
64 Correct 90 ms 72492 KB Output is correct
65 Correct 87 ms 72188 KB Output is correct
66 Correct 85 ms 72220 KB Output is correct
67 Correct 88 ms 72200 KB Output is correct
68 Correct 86 ms 72268 KB Output is correct
69 Correct 1 ms 320 KB Output is correct
70 Incorrect 1 ms 340 KB Output isn't correct
71 Halted 0 ms 0 KB -