#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
typedef long long ll;
typedef pair<ll , ll> pll;
const ll maxn = 2e5 + 17;
string s;
vector<ll> a , b;
vector<pll> u;
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);
}
}
ll res = 0;
for(ll k = 0 ; k < n ; k++){
u.clear();
for(ll i = 0 ; i < n ; i++){
u.push_back({a[i] , b[(i + k) % n]});
if(u.back().first > u.back().second){
swap(u.back().first , u.back().second);
}
}
ll cur = 0;
for(ll i = 0 ; i < n ; i++){
for(ll j = i + 1 ; j < n ; j++){
bool c = (u[i].first > u[j].first) , d = (u[i].second > u[j].second);
if(c ^ d) continue;
if(c){
cur += (u[i].first < u[j].second);
} else {
cur += (u[j].first < u[i].second);
}
}
}
res = max(res , cur);
}
cout<<res<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
23 ms |
340 KB |
Output is correct |
15 |
Correct |
23 ms |
340 KB |
Output is correct |
16 |
Correct |
20 ms |
352 KB |
Output is correct |
17 |
Correct |
20 ms |
348 KB |
Output is correct |
18 |
Correct |
14 ms |
340 KB |
Output is correct |
19 |
Correct |
25 ms |
344 KB |
Output is correct |
20 |
Correct |
16 ms |
340 KB |
Output is correct |
21 |
Correct |
20 ms |
356 KB |
Output is correct |
22 |
Correct |
21 ms |
340 KB |
Output is correct |
23 |
Correct |
6 ms |
340 KB |
Output is correct |
24 |
Correct |
13 ms |
344 KB |
Output is correct |
25 |
Correct |
14 ms |
320 KB |
Output is correct |
26 |
Correct |
14 ms |
356 KB |
Output is correct |
27 |
Correct |
16 ms |
348 KB |
Output is correct |
28 |
Correct |
18 ms |
352 KB |
Output is correct |
29 |
Correct |
14 ms |
340 KB |
Output is correct |
30 |
Correct |
21 ms |
340 KB |
Output is correct |
31 |
Correct |
18 ms |
340 KB |
Output is correct |
32 |
Correct |
18 ms |
340 KB |
Output is correct |
33 |
Correct |
20 ms |
352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
23 ms |
340 KB |
Output is correct |
15 |
Correct |
23 ms |
340 KB |
Output is correct |
16 |
Correct |
20 ms |
352 KB |
Output is correct |
17 |
Correct |
20 ms |
348 KB |
Output is correct |
18 |
Correct |
14 ms |
340 KB |
Output is correct |
19 |
Correct |
25 ms |
344 KB |
Output is correct |
20 |
Correct |
16 ms |
340 KB |
Output is correct |
21 |
Correct |
20 ms |
356 KB |
Output is correct |
22 |
Correct |
21 ms |
340 KB |
Output is correct |
23 |
Correct |
6 ms |
340 KB |
Output is correct |
24 |
Correct |
13 ms |
344 KB |
Output is correct |
25 |
Correct |
14 ms |
320 KB |
Output is correct |
26 |
Correct |
14 ms |
356 KB |
Output is correct |
27 |
Correct |
16 ms |
348 KB |
Output is correct |
28 |
Correct |
18 ms |
352 KB |
Output is correct |
29 |
Correct |
14 ms |
340 KB |
Output is correct |
30 |
Correct |
21 ms |
340 KB |
Output is correct |
31 |
Correct |
18 ms |
340 KB |
Output is correct |
32 |
Correct |
18 ms |
340 KB |
Output is correct |
33 |
Correct |
20 ms |
352 KB |
Output is correct |
34 |
Execution timed out |
2075 ms |
340 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
23 ms |
340 KB |
Output is correct |
15 |
Correct |
23 ms |
340 KB |
Output is correct |
16 |
Correct |
20 ms |
352 KB |
Output is correct |
17 |
Correct |
20 ms |
348 KB |
Output is correct |
18 |
Correct |
14 ms |
340 KB |
Output is correct |
19 |
Correct |
25 ms |
344 KB |
Output is correct |
20 |
Correct |
16 ms |
340 KB |
Output is correct |
21 |
Correct |
20 ms |
356 KB |
Output is correct |
22 |
Correct |
21 ms |
340 KB |
Output is correct |
23 |
Correct |
6 ms |
340 KB |
Output is correct |
24 |
Correct |
13 ms |
344 KB |
Output is correct |
25 |
Correct |
14 ms |
320 KB |
Output is correct |
26 |
Correct |
14 ms |
356 KB |
Output is correct |
27 |
Correct |
16 ms |
348 KB |
Output is correct |
28 |
Correct |
18 ms |
352 KB |
Output is correct |
29 |
Correct |
14 ms |
340 KB |
Output is correct |
30 |
Correct |
21 ms |
340 KB |
Output is correct |
31 |
Correct |
18 ms |
340 KB |
Output is correct |
32 |
Correct |
18 ms |
340 KB |
Output is correct |
33 |
Correct |
20 ms |
352 KB |
Output is correct |
34 |
Execution timed out |
2075 ms |
340 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |