#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
typedef long long ll;
typedef pair<ll , ll> pll;
const ll maxn = 4e5 + 17;
string s;
vector<ll> a , b;
ll ps[maxn];
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n;
cin>>n>>s;
for(ll i = 0 ; i < (n << 1) ; i++){
if(s[i] == 'B'){
a.push_back(i);
} else {
b.push_back(i);
}
}
ps[0] = (s[0] == 'B');
for(ll i = 1 ; i < (n << 1) ; i++){
ps[i] = ps[i - 1] + (s[i] == 'B');
}
ll res = 0;
for(ll k = 0 ; k < n ; k++){
ll cur = 0;
for(ll t = 0 ; t < n ; t++){
ll i = a[t] , j = b[(t + k) % n];
if(i < j){
ll h1 = ps[j] - ps[i] , h0 = j - i - 1 - h1 , b0 = n - 1 - h0 , h = max(0ll , h1 - b0);
cur += j - i - 1 - (h << 1);
} else {
ll d = (n << 1) - (i - j + 1) , h1 = n - ps[i] + ps[j] , h0 = d - h1 , b0 = n - 1 - h0 , h = max(0ll , h1 - b0);
cur += d - (h << 1);
}
}
cur >>= 1;
res = max(res , cur);
}
cout<<res<<'\n';
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 |
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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 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 |
# |
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 |
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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 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 |
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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
20 ms |
416 KB |
Output is correct |
35 |
Correct |
19 ms |
428 KB |
Output is correct |
36 |
Correct |
18 ms |
340 KB |
Output is correct |
37 |
Correct |
17 ms |
340 KB |
Output is correct |
38 |
Correct |
16 ms |
424 KB |
Output is correct |
39 |
Correct |
19 ms |
340 KB |
Output is correct |
40 |
Correct |
17 ms |
340 KB |
Output is correct |
41 |
Correct |
14 ms |
340 KB |
Output is correct |
42 |
Correct |
18 ms |
332 KB |
Output is correct |
43 |
Correct |
18 ms |
340 KB |
Output is correct |
44 |
Correct |
16 ms |
340 KB |
Output is correct |
45 |
Correct |
17 ms |
340 KB |
Output is correct |
46 |
Correct |
18 ms |
428 KB |
Output is correct |
47 |
Correct |
18 ms |
340 KB |
Output is correct |
48 |
Correct |
19 ms |
436 KB |
Output is correct |
49 |
Correct |
16 ms |
396 KB |
Output is correct |
50 |
Correct |
19 ms |
420 KB |
Output is correct |
51 |
Correct |
23 ms |
416 KB |
Output is correct |
52 |
Correct |
19 ms |
436 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 |
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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
20 ms |
416 KB |
Output is correct |
35 |
Correct |
19 ms |
428 KB |
Output is correct |
36 |
Correct |
18 ms |
340 KB |
Output is correct |
37 |
Correct |
17 ms |
340 KB |
Output is correct |
38 |
Correct |
16 ms |
424 KB |
Output is correct |
39 |
Correct |
19 ms |
340 KB |
Output is correct |
40 |
Correct |
17 ms |
340 KB |
Output is correct |
41 |
Correct |
14 ms |
340 KB |
Output is correct |
42 |
Correct |
18 ms |
332 KB |
Output is correct |
43 |
Correct |
18 ms |
340 KB |
Output is correct |
44 |
Correct |
16 ms |
340 KB |
Output is correct |
45 |
Correct |
17 ms |
340 KB |
Output is correct |
46 |
Correct |
18 ms |
428 KB |
Output is correct |
47 |
Correct |
18 ms |
340 KB |
Output is correct |
48 |
Correct |
19 ms |
436 KB |
Output is correct |
49 |
Correct |
16 ms |
396 KB |
Output is correct |
50 |
Correct |
19 ms |
420 KB |
Output is correct |
51 |
Correct |
23 ms |
416 KB |
Output is correct |
52 |
Correct |
19 ms |
436 KB |
Output is correct |
53 |
Execution timed out |
2055 ms |
7892 KB |
Time limit exceeded |
54 |
Halted |
0 ms |
0 KB |
- |