#include<iostream>
#include<algorithm>
#include<vector>
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
const int N = 2e5 + 8;
int n, n2;
char s[N << 2];
char c[N << 1];
int solve(int l, int r) {
copy(s + l, s + r + 1, c + 1);
vector<int> vec[2];
for (int i = n; i; --i)
vec[c[i] == 'W'].push_back(i);
int sum(0);
for (int i = n + 1, x, y, p; i <= n2; ++i) {
x = c[i] == 'B';
y = vec[x].back(); vec[x].pop_back();
sum += vec[x].size();
sum += lower_bound(all(vec[x ^ 1]), y, greater<int>()) - vec[x ^ 1].begin();
}
return sum;
}
int main() {
cin.tie(NULL)->sync_with_stdio(false);
cin >> n >> (s + 1);
n2 = n << 1;
copy(s + 1, s + n2 + 1, s + n2 + 1);
int ans(0);
for (int i = 1; i <= n; ++i)
ans = max(ans, solve(i, i + n2 - 1));
cout << ans << '\n';
}
/** /\_/\
* (= ._.)
* / >0 \>1
**/
Compilation message
monochrome.cpp: In function 'int solve(int, int)':
monochrome.cpp:21:31: warning: unused variable 'p' [-Wunused-variable]
21 | for (int i = n + 1, x, y, p; i <= n2; ++i) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
3 ms |
212 KB |
Output is correct |
15 |
Correct |
3 ms |
336 KB |
Output is correct |
16 |
Correct |
3 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
328 KB |
Output is correct |
30 |
Correct |
2 ms |
212 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
3 ms |
212 KB |
Output is correct |
15 |
Correct |
3 ms |
336 KB |
Output is correct |
16 |
Correct |
3 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
328 KB |
Output is correct |
30 |
Correct |
2 ms |
212 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
340 KB |
Output is correct |
34 |
Correct |
134 ms |
360 KB |
Output is correct |
35 |
Correct |
148 ms |
360 KB |
Output is correct |
36 |
Correct |
133 ms |
340 KB |
Output is correct |
37 |
Correct |
122 ms |
344 KB |
Output is correct |
38 |
Correct |
67 ms |
372 KB |
Output is correct |
39 |
Correct |
82 ms |
340 KB |
Output is correct |
40 |
Correct |
80 ms |
332 KB |
Output is correct |
41 |
Correct |
77 ms |
348 KB |
Output is correct |
42 |
Correct |
127 ms |
344 KB |
Output is correct |
43 |
Correct |
85 ms |
364 KB |
Output is correct |
44 |
Correct |
92 ms |
340 KB |
Output is correct |
45 |
Correct |
76 ms |
352 KB |
Output is correct |
46 |
Correct |
78 ms |
348 KB |
Output is correct |
47 |
Correct |
85 ms |
368 KB |
Output is correct |
48 |
Correct |
80 ms |
356 KB |
Output is correct |
49 |
Correct |
66 ms |
348 KB |
Output is correct |
50 |
Correct |
70 ms |
368 KB |
Output is correct |
51 |
Correct |
70 ms |
364 KB |
Output is correct |
52 |
Correct |
83 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
3 ms |
212 KB |
Output is correct |
15 |
Correct |
3 ms |
336 KB |
Output is correct |
16 |
Correct |
3 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
328 KB |
Output is correct |
30 |
Correct |
2 ms |
212 KB |
Output is correct |
31 |
Correct |
2 ms |
332 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
340 KB |
Output is correct |
34 |
Correct |
134 ms |
360 KB |
Output is correct |
35 |
Correct |
148 ms |
360 KB |
Output is correct |
36 |
Correct |
133 ms |
340 KB |
Output is correct |
37 |
Correct |
122 ms |
344 KB |
Output is correct |
38 |
Correct |
67 ms |
372 KB |
Output is correct |
39 |
Correct |
82 ms |
340 KB |
Output is correct |
40 |
Correct |
80 ms |
332 KB |
Output is correct |
41 |
Correct |
77 ms |
348 KB |
Output is correct |
42 |
Correct |
127 ms |
344 KB |
Output is correct |
43 |
Correct |
85 ms |
364 KB |
Output is correct |
44 |
Correct |
92 ms |
340 KB |
Output is correct |
45 |
Correct |
76 ms |
352 KB |
Output is correct |
46 |
Correct |
78 ms |
348 KB |
Output is correct |
47 |
Correct |
85 ms |
368 KB |
Output is correct |
48 |
Correct |
80 ms |
356 KB |
Output is correct |
49 |
Correct |
66 ms |
348 KB |
Output is correct |
50 |
Correct |
70 ms |
368 KB |
Output is correct |
51 |
Correct |
70 ms |
364 KB |
Output is correct |
52 |
Correct |
83 ms |
340 KB |
Output is correct |
53 |
Execution timed out |
2072 ms |
3540 KB |
Time limit exceeded |
54 |
Halted |
0 ms |
0 KB |
- |