#include<bits/stdc++.h>
#define x first
#define y second
#define sz(v) (int)v.size()
#define pb push_back
#define nl "\n"
using namespace std;
const int N = (int)1e6 + 7;
const int inf = (int)1e9 + 7;
int n, pos[N], p[N], e[N];
bool dp[500][16][1 << 16];
string s;
void calc(int v, int l, int r) {
if(l == r) {
for(int i = 0; i < n; ++i) {
dp[v][i][1 << i] = 1;
}
return;
}
bool tp = (s[l + 1] == 'a');
int mid = e[l];
calc(v * 2, l + 4, mid - 1);
calc(v * 2 + 1, mid + 1, r - 1);
for(int mask = 0; mask < (1 << n); ++mask) {
int msk = (((1 << n) - 1) ^ mask);
for(int s = msk; s; s = (s - 1) & msk) {
for(int x = 0; x < n; ++x) {
for(int y = 0; y < n; ++y) {
dp[v][(tp ? max(x, y) : min(x, y))][mask | s] |= (dp[v * 2][x][mask] & dp[v * 2 + 1][y][s]);
}
}
}
}
}
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cin >> s;
for(int i = 0; i < sz(s); ++i) {
if(s[i] == '?') {
pos[i] = ++n;
}
}
stack<int> st;
for(int i = 0; i < sz(s); ++i) {
if(s[i] == 'm') st.push(i);
if(s[i] == ',') {
assert(!st.empty());
e[st.top()] = i;
st.pop();
}
}
calc(1, 0, sz(s) - 1);
int ans = 0;
for(int i = 0; i < n; ++i) ans += dp[1][i][(1 << n) - 1];
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
972 KB |
Output is correct |
2 |
Correct |
40 ms |
904 KB |
Output is correct |
3 |
Correct |
43 ms |
944 KB |
Output is correct |
4 |
Correct |
39 ms |
984 KB |
Output is correct |
5 |
Correct |
37 ms |
904 KB |
Output is correct |
6 |
Correct |
36 ms |
884 KB |
Output is correct |
7 |
Correct |
36 ms |
948 KB |
Output is correct |
8 |
Correct |
34 ms |
920 KB |
Output is correct |
9 |
Correct |
36 ms |
948 KB |
Output is correct |
10 |
Correct |
37 ms |
912 KB |
Output is correct |
11 |
Correct |
41 ms |
956 KB |
Output is correct |
12 |
Correct |
40 ms |
912 KB |
Output is correct |
13 |
Correct |
38 ms |
940 KB |
Output is correct |
14 |
Correct |
36 ms |
968 KB |
Output is correct |
15 |
Correct |
36 ms |
944 KB |
Output is correct |
16 |
Correct |
38 ms |
908 KB |
Output is correct |
17 |
Correct |
38 ms |
936 KB |
Output is correct |
18 |
Correct |
35 ms |
1084 KB |
Output is correct |
19 |
Correct |
41 ms |
928 KB |
Output is correct |
20 |
Correct |
41 ms |
956 KB |
Output is correct |
21 |
Correct |
41 ms |
952 KB |
Output is correct |
22 |
Correct |
38 ms |
968 KB |
Output is correct |
23 |
Correct |
36 ms |
972 KB |
Output is correct |
24 |
Correct |
35 ms |
980 KB |
Output is correct |
25 |
Correct |
9 ms |
852 KB |
Output is correct |
26 |
Correct |
9 ms |
840 KB |
Output is correct |
27 |
Correct |
10 ms |
824 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
972 KB |
Output is correct |
2 |
Correct |
40 ms |
904 KB |
Output is correct |
3 |
Correct |
43 ms |
944 KB |
Output is correct |
4 |
Correct |
39 ms |
984 KB |
Output is correct |
5 |
Correct |
37 ms |
904 KB |
Output is correct |
6 |
Correct |
36 ms |
884 KB |
Output is correct |
7 |
Correct |
36 ms |
948 KB |
Output is correct |
8 |
Correct |
34 ms |
920 KB |
Output is correct |
9 |
Correct |
36 ms |
948 KB |
Output is correct |
10 |
Correct |
37 ms |
912 KB |
Output is correct |
11 |
Correct |
41 ms |
956 KB |
Output is correct |
12 |
Correct |
40 ms |
912 KB |
Output is correct |
13 |
Correct |
38 ms |
940 KB |
Output is correct |
14 |
Correct |
36 ms |
968 KB |
Output is correct |
15 |
Correct |
36 ms |
944 KB |
Output is correct |
16 |
Correct |
38 ms |
908 KB |
Output is correct |
17 |
Correct |
38 ms |
936 KB |
Output is correct |
18 |
Correct |
35 ms |
1084 KB |
Output is correct |
19 |
Correct |
41 ms |
928 KB |
Output is correct |
20 |
Correct |
41 ms |
956 KB |
Output is correct |
21 |
Correct |
41 ms |
952 KB |
Output is correct |
22 |
Correct |
38 ms |
968 KB |
Output is correct |
23 |
Correct |
36 ms |
972 KB |
Output is correct |
24 |
Correct |
35 ms |
980 KB |
Output is correct |
25 |
Correct |
9 ms |
852 KB |
Output is correct |
26 |
Correct |
9 ms |
840 KB |
Output is correct |
27 |
Correct |
10 ms |
824 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Execution timed out |
1066 ms |
1560 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
28 ms |
11216 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
972 KB |
Output is correct |
2 |
Correct |
40 ms |
904 KB |
Output is correct |
3 |
Correct |
43 ms |
944 KB |
Output is correct |
4 |
Correct |
39 ms |
984 KB |
Output is correct |
5 |
Correct |
37 ms |
904 KB |
Output is correct |
6 |
Correct |
36 ms |
884 KB |
Output is correct |
7 |
Correct |
36 ms |
948 KB |
Output is correct |
8 |
Correct |
34 ms |
920 KB |
Output is correct |
9 |
Correct |
36 ms |
948 KB |
Output is correct |
10 |
Correct |
37 ms |
912 KB |
Output is correct |
11 |
Correct |
41 ms |
956 KB |
Output is correct |
12 |
Correct |
40 ms |
912 KB |
Output is correct |
13 |
Correct |
38 ms |
940 KB |
Output is correct |
14 |
Correct |
36 ms |
968 KB |
Output is correct |
15 |
Correct |
36 ms |
944 KB |
Output is correct |
16 |
Correct |
38 ms |
908 KB |
Output is correct |
17 |
Correct |
38 ms |
936 KB |
Output is correct |
18 |
Correct |
35 ms |
1084 KB |
Output is correct |
19 |
Correct |
41 ms |
928 KB |
Output is correct |
20 |
Correct |
41 ms |
956 KB |
Output is correct |
21 |
Correct |
41 ms |
952 KB |
Output is correct |
22 |
Correct |
38 ms |
968 KB |
Output is correct |
23 |
Correct |
36 ms |
972 KB |
Output is correct |
24 |
Correct |
35 ms |
980 KB |
Output is correct |
25 |
Correct |
9 ms |
852 KB |
Output is correct |
26 |
Correct |
9 ms |
840 KB |
Output is correct |
27 |
Correct |
10 ms |
824 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Execution timed out |
1066 ms |
1560 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
972 KB |
Output is correct |
2 |
Correct |
40 ms |
904 KB |
Output is correct |
3 |
Correct |
43 ms |
944 KB |
Output is correct |
4 |
Correct |
39 ms |
984 KB |
Output is correct |
5 |
Correct |
37 ms |
904 KB |
Output is correct |
6 |
Correct |
36 ms |
884 KB |
Output is correct |
7 |
Correct |
36 ms |
948 KB |
Output is correct |
8 |
Correct |
34 ms |
920 KB |
Output is correct |
9 |
Correct |
36 ms |
948 KB |
Output is correct |
10 |
Correct |
37 ms |
912 KB |
Output is correct |
11 |
Correct |
41 ms |
956 KB |
Output is correct |
12 |
Correct |
40 ms |
912 KB |
Output is correct |
13 |
Correct |
38 ms |
940 KB |
Output is correct |
14 |
Correct |
36 ms |
968 KB |
Output is correct |
15 |
Correct |
36 ms |
944 KB |
Output is correct |
16 |
Correct |
38 ms |
908 KB |
Output is correct |
17 |
Correct |
38 ms |
936 KB |
Output is correct |
18 |
Correct |
35 ms |
1084 KB |
Output is correct |
19 |
Correct |
41 ms |
928 KB |
Output is correct |
20 |
Correct |
41 ms |
956 KB |
Output is correct |
21 |
Correct |
41 ms |
952 KB |
Output is correct |
22 |
Correct |
38 ms |
968 KB |
Output is correct |
23 |
Correct |
36 ms |
972 KB |
Output is correct |
24 |
Correct |
35 ms |
980 KB |
Output is correct |
25 |
Correct |
9 ms |
852 KB |
Output is correct |
26 |
Correct |
9 ms |
840 KB |
Output is correct |
27 |
Correct |
10 ms |
824 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Execution timed out |
1066 ms |
1560 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |