#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const ll mod = 1000000007;
int n;
string s;
const int maxn = 310;
int max_val[maxn][maxn];
int pref[maxn];
void solve()
{
cin >> n >> s;
s = "#" + s;
int cnt = 0;
for (int i = 1; i <= n; i ++)
{
if (s[i] == 'x')
cnt ++;
}
int res = 0;
for (int mask = 0; mask < (1 << cnt); mask ++)
{
int bit = 0;
string t = s;
for (int i = 1; i <= n; i ++)
{
if (t[i] == 'x')
{
//cout << "here " << mask << " " << bit << " " << (mask & (1 << bit)) << endl;
if ((mask & (1 << bit)) > 0)
t[i] = '(';
else
t[i] = ')';
bit ++;
}
}
bool done = false;
for (int i = 1; i <= n; i ++)
{
pref[i] = pref[i - 1];
if (t[i] == '(')
pref[i] ++;
else
pref[i] --;
}
if (abs(pref[n]) % 2 == 1)
{
continue;
}
int d = pref[n];
int lf = 1;
while(lf <= n && pref[lf] >= 0)
lf ++;
lf --;
int rf = n;
while(rf > 0 && pref[rf] - d >= 0)
rf --;
for (int i = 1; i <= n; i ++)
{
int x = pref[i];
for (int j = i; j <= n; j ++)
{
x = max(x, pref[j]);
max_val[i][j] = x;
}
}
for (int r = n; r >= rf - 1 && !done; r --)
{
for (int l = 1; l <= lf + 1; l ++)
{
///cout << "HERE " << l << " " << r << endl;
if (pref[r] - pref[l - 1] != d / 2)
continue;
int val = max_val[l][r] - pref[l - 1];
val = -val;
val = val + pref[l - 1];
if (val >= 0)
{
done = true;
break;
}
}
}
bool tf = true;
for (int d = 1; d <= n; d ++)
{
if (pref[d] < 0)
{
tf = false;
break;
}
}
if (pref[n] != 0)
tf = false;
if (tf)
{
///cout << i << " : " << j << endl;
done = true;
}
if (done)
res ++;
//cout << t << " " << done << endl;
//cout << lf << " " << rf << endl;
}
cout << res << endl;
}
int main()
{
speed();
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
12 ms |
344 KB |
Output is correct |
22 |
Correct |
16 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
16 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
11 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
17 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
12 ms |
344 KB |
Output is correct |
22 |
Correct |
16 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
16 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
11 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
17 ms |
344 KB |
Output is correct |
32 |
Correct |
12 ms |
348 KB |
Output is correct |
33 |
Correct |
4 ms |
348 KB |
Output is correct |
34 |
Correct |
476 ms |
476 KB |
Output is correct |
35 |
Correct |
11 ms |
348 KB |
Output is correct |
36 |
Correct |
236 ms |
564 KB |
Output is correct |
37 |
Correct |
1026 ms |
560 KB |
Output is correct |
38 |
Correct |
3961 ms |
568 KB |
Output is correct |
39 |
Correct |
11 ms |
348 KB |
Output is correct |
40 |
Correct |
3336 ms |
540 KB |
Output is correct |
41 |
Correct |
2859 ms |
348 KB |
Output is correct |
42 |
Correct |
3619 ms |
552 KB |
Output is correct |
43 |
Correct |
2101 ms |
564 KB |
Output is correct |
44 |
Correct |
285 ms |
348 KB |
Output is correct |
45 |
Correct |
4187 ms |
560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
12 ms |
344 KB |
Output is correct |
22 |
Correct |
16 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
16 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
11 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
17 ms |
344 KB |
Output is correct |
32 |
Correct |
12 ms |
348 KB |
Output is correct |
33 |
Correct |
4 ms |
348 KB |
Output is correct |
34 |
Correct |
476 ms |
476 KB |
Output is correct |
35 |
Correct |
11 ms |
348 KB |
Output is correct |
36 |
Correct |
236 ms |
564 KB |
Output is correct |
37 |
Correct |
1026 ms |
560 KB |
Output is correct |
38 |
Correct |
3961 ms |
568 KB |
Output is correct |
39 |
Correct |
11 ms |
348 KB |
Output is correct |
40 |
Correct |
3336 ms |
540 KB |
Output is correct |
41 |
Correct |
2859 ms |
348 KB |
Output is correct |
42 |
Correct |
3619 ms |
552 KB |
Output is correct |
43 |
Correct |
2101 ms |
564 KB |
Output is correct |
44 |
Correct |
285 ms |
348 KB |
Output is correct |
45 |
Correct |
4187 ms |
560 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
468 KB |
Output is correct |
49 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
50 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
12 ms |
344 KB |
Output is correct |
22 |
Correct |
16 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
16 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
11 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
17 ms |
344 KB |
Output is correct |
32 |
Correct |
12 ms |
348 KB |
Output is correct |
33 |
Correct |
4 ms |
348 KB |
Output is correct |
34 |
Correct |
476 ms |
476 KB |
Output is correct |
35 |
Correct |
11 ms |
348 KB |
Output is correct |
36 |
Correct |
236 ms |
564 KB |
Output is correct |
37 |
Correct |
1026 ms |
560 KB |
Output is correct |
38 |
Correct |
3961 ms |
568 KB |
Output is correct |
39 |
Correct |
11 ms |
348 KB |
Output is correct |
40 |
Correct |
3336 ms |
540 KB |
Output is correct |
41 |
Correct |
2859 ms |
348 KB |
Output is correct |
42 |
Correct |
3619 ms |
552 KB |
Output is correct |
43 |
Correct |
2101 ms |
564 KB |
Output is correct |
44 |
Correct |
285 ms |
348 KB |
Output is correct |
45 |
Correct |
4187 ms |
560 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
468 KB |
Output is correct |
49 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
50 |
Halted |
0 ms |
0 KB |
- |