Submission #633477

# Submission time Handle Problem Language Result Execution time Memory
633477 2022-08-22T14:25:16 Z Ooops_sorry Homework (CEOI22_homework) C++14
100 / 100
141 ms 126460 KB
#include<bits/stdc++.h>

using namespace std;

mt19937 rnd(51);

#define ll long long
#define pb push_back
#define ld long double

const int INF = 1e9;
string s;
vector<int> go;
int n;

int solve(int l, int r) {
    if (s[l] == '?') {
        return 1;
    }
    int i = go[l + 3];
    if (s[l + 1] == 'a') {
        return min(solve(l + 4, i - 1), solve(i + 1, r - 1));
    } else {
        return solve(l + 4, i - 1) + solve(i + 1, r - 1);
    }
}

int solve2(int l, int r) {
    if (s[l] == '?') {
        return 1;
    }
    int i = go[l + 3];
    if (s[l + 1] == 'a') {
        return solve2(l + 4, i - 1) + solve2(i + 1, r - 1);
    } else {
        return min(solve2(l + 4, i - 1), solve2(i + 1, r - 1));
    }
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif // LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> s;
    n = s.size();
    go.resize(n);
    deque<pair<int,int>> q;
    int cnt = 1;
    for (int i = n - 1; i >= 0; i--) {
        if (s[i] == ')') {
            q.pb({i, -1});
            cnt++;
        } else if (s[i] == ',') {
            q.back().second = i;
        } else if (s[i] == '(') {
            go[i] = q.back().second;
            q.pop_back();
        }
    }
    int mx = cnt - solve(0, n - 1) + 1;
    int mn = solve2(0, n - 1);
    cout << mx - mn + 1 << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 0 ms 320 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 324 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 0 ms 320 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 324 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 324 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 324 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 324 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 1 ms 324 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 125892 KB Output is correct
2 Correct 125 ms 126460 KB Output is correct
3 Correct 124 ms 106472 KB Output is correct
4 Correct 129 ms 108008 KB Output is correct
5 Correct 123 ms 123464 KB Output is correct
6 Correct 120 ms 123724 KB Output is correct
7 Correct 128 ms 122964 KB Output is correct
8 Correct 125 ms 123156 KB Output is correct
9 Correct 115 ms 106744 KB Output is correct
10 Correct 122 ms 106240 KB Output is correct
11 Correct 122 ms 108296 KB Output is correct
12 Correct 123 ms 106636 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 0 ms 320 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 324 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 324 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 324 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 324 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 1 ms 324 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 0 ms 340 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 328 KB Output is correct
66 Correct 1 ms 328 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 332 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 0 ms 332 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 0 ms 340 KB Output is correct
74 Correct 1 ms 324 KB Output is correct
75 Correct 1 ms 328 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 1 ms 340 KB Output is correct
81 Correct 1 ms 340 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 328 KB Output is correct
85 Correct 0 ms 320 KB Output is correct
86 Correct 0 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 0 ms 320 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 324 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 324 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 324 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 324 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 1 ms 324 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 125 ms 125892 KB Output is correct
58 Correct 125 ms 126460 KB Output is correct
59 Correct 124 ms 106472 KB Output is correct
60 Correct 129 ms 108008 KB Output is correct
61 Correct 123 ms 123464 KB Output is correct
62 Correct 120 ms 123724 KB Output is correct
63 Correct 128 ms 122964 KB Output is correct
64 Correct 125 ms 123156 KB Output is correct
65 Correct 115 ms 106744 KB Output is correct
66 Correct 122 ms 106240 KB Output is correct
67 Correct 122 ms 108296 KB Output is correct
68 Correct 123 ms 106636 KB Output is correct
69 Correct 0 ms 212 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 0 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 0 ms 340 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 328 KB Output is correct
79 Correct 1 ms 328 KB Output is correct
80 Correct 1 ms 340 KB Output is correct
81 Correct 1 ms 340 KB Output is correct
82 Correct 1 ms 332 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 0 ms 332 KB Output is correct
85 Correct 1 ms 340 KB Output is correct
86 Correct 0 ms 340 KB Output is correct
87 Correct 1 ms 324 KB Output is correct
88 Correct 1 ms 328 KB Output is correct
89 Correct 1 ms 340 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 1 ms 340 KB Output is correct
93 Correct 1 ms 340 KB Output is correct
94 Correct 1 ms 340 KB Output is correct
95 Correct 1 ms 340 KB Output is correct
96 Correct 1 ms 340 KB Output is correct
97 Correct 1 ms 328 KB Output is correct
98 Correct 0 ms 320 KB Output is correct
99 Correct 0 ms 324 KB Output is correct
100 Correct 89 ms 41304 KB Output is correct
101 Correct 89 ms 40324 KB Output is correct
102 Correct 79 ms 40260 KB Output is correct
103 Correct 82 ms 40604 KB Output is correct
104 Correct 75 ms 39640 KB Output is correct
105 Correct 108 ms 62224 KB Output is correct
106 Correct 113 ms 61812 KB Output is correct
107 Correct 99 ms 67244 KB Output is correct
108 Correct 97 ms 68024 KB Output is correct
109 Correct 107 ms 63172 KB Output is correct
110 Correct 97 ms 41452 KB Output is correct
111 Correct 93 ms 40408 KB Output is correct
112 Correct 88 ms 40776 KB Output is correct
113 Correct 87 ms 40264 KB Output is correct
114 Correct 86 ms 40772 KB Output is correct
115 Correct 141 ms 108064 KB Output is correct
116 Correct 134 ms 107208 KB Output is correct
117 Correct 126 ms 123560 KB Output is correct
118 Correct 133 ms 122884 KB Output is correct
119 Correct 131 ms 106912 KB Output is correct
120 Correct 106 ms 41012 KB Output is correct
121 Correct 85 ms 41088 KB Output is correct
122 Correct 94 ms 40904 KB Output is correct
123 Correct 95 ms 41060 KB Output is correct
124 Correct 81 ms 64840 KB Output is correct
125 Correct 80 ms 64772 KB Output is correct
126 Correct 83 ms 64272 KB Output is correct
127 Correct 82 ms 65068 KB Output is correct
128 Correct 38 ms 21712 KB Output is correct
129 Correct 36 ms 21444 KB Output is correct
130 Correct 31 ms 21792 KB Output is correct
131 Correct 1 ms 212 KB Output is correct