#include<bits/stdc++.h>
#define st first
#define nd second
#define eb emplace_back
#define pb push_back
#define pp pop_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
void debug(){cerr<<"\n";}
template<typename H, typename... T>
void debug(H h, T... t){cerr<<h;if(sizeof...(t))cerr<<", ";debug(t...);};
#define deb(x...) cerr<<#x<<" = ";debug(x);
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=1e5+5, INF=1e9+5;
int solve(int n, string s){
int wsk=n, wsk2=n;
vi V(n);
for(int i=0; i<n; i++){
//deb(wsk, wsk2);
if(s[i]=='B'){
while(s[wsk]=='B')wsk++;
V[wsk-n]=i;
wsk++;
}
else{
while(s[wsk2]=='W')wsk2++;
V[wsk2-n]=i;
wsk2++;
}
}
int ans=0;
for(int i=0; i<n; i++){
//deb(V[i]);
for(int j=i+1; j<n; j++){
if(V[i]<V[j])ans++;
}
}
return ans;
}
int main(){
//ios_base::sync_with_stdio(0);cin.tie(0);
int n;
cin>>n;
string s;
cin>>s;
int ans=0;
for(int i=0; i<n; i++){
for(int j=1; j<n+n; j++){
swap(s[j-1], s[j]);
}
ans=max(ans, solve(n, s));
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 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 |
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 |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
304 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 |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 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 |
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 |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
14 ms |
308 KB |
Output is correct |
15 |
Correct |
15 ms |
212 KB |
Output is correct |
16 |
Correct |
15 ms |
308 KB |
Output is correct |
17 |
Correct |
14 ms |
212 KB |
Output is correct |
18 |
Correct |
10 ms |
212 KB |
Output is correct |
19 |
Correct |
12 ms |
300 KB |
Output is correct |
20 |
Correct |
11 ms |
308 KB |
Output is correct |
21 |
Correct |
11 ms |
212 KB |
Output is correct |
22 |
Correct |
11 ms |
212 KB |
Output is correct |
23 |
Correct |
5 ms |
212 KB |
Output is correct |
24 |
Correct |
10 ms |
304 KB |
Output is correct |
25 |
Correct |
8 ms |
300 KB |
Output is correct |
26 |
Correct |
10 ms |
212 KB |
Output is correct |
27 |
Correct |
10 ms |
212 KB |
Output is correct |
28 |
Correct |
12 ms |
212 KB |
Output is correct |
29 |
Correct |
8 ms |
308 KB |
Output is correct |
30 |
Correct |
9 ms |
308 KB |
Output is correct |
31 |
Correct |
12 ms |
308 KB |
Output is correct |
32 |
Correct |
12 ms |
212 KB |
Output is correct |
33 |
Correct |
13 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 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 |
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 |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
14 ms |
308 KB |
Output is correct |
15 |
Correct |
15 ms |
212 KB |
Output is correct |
16 |
Correct |
15 ms |
308 KB |
Output is correct |
17 |
Correct |
14 ms |
212 KB |
Output is correct |
18 |
Correct |
10 ms |
212 KB |
Output is correct |
19 |
Correct |
12 ms |
300 KB |
Output is correct |
20 |
Correct |
11 ms |
308 KB |
Output is correct |
21 |
Correct |
11 ms |
212 KB |
Output is correct |
22 |
Correct |
11 ms |
212 KB |
Output is correct |
23 |
Correct |
5 ms |
212 KB |
Output is correct |
24 |
Correct |
10 ms |
304 KB |
Output is correct |
25 |
Correct |
8 ms |
300 KB |
Output is correct |
26 |
Correct |
10 ms |
212 KB |
Output is correct |
27 |
Correct |
10 ms |
212 KB |
Output is correct |
28 |
Correct |
12 ms |
212 KB |
Output is correct |
29 |
Correct |
8 ms |
308 KB |
Output is correct |
30 |
Correct |
9 ms |
308 KB |
Output is correct |
31 |
Correct |
12 ms |
308 KB |
Output is correct |
32 |
Correct |
12 ms |
212 KB |
Output is correct |
33 |
Correct |
13 ms |
212 KB |
Output is correct |
34 |
Execution timed out |
2089 ms |
212 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 |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 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 |
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 |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
14 ms |
308 KB |
Output is correct |
15 |
Correct |
15 ms |
212 KB |
Output is correct |
16 |
Correct |
15 ms |
308 KB |
Output is correct |
17 |
Correct |
14 ms |
212 KB |
Output is correct |
18 |
Correct |
10 ms |
212 KB |
Output is correct |
19 |
Correct |
12 ms |
300 KB |
Output is correct |
20 |
Correct |
11 ms |
308 KB |
Output is correct |
21 |
Correct |
11 ms |
212 KB |
Output is correct |
22 |
Correct |
11 ms |
212 KB |
Output is correct |
23 |
Correct |
5 ms |
212 KB |
Output is correct |
24 |
Correct |
10 ms |
304 KB |
Output is correct |
25 |
Correct |
8 ms |
300 KB |
Output is correct |
26 |
Correct |
10 ms |
212 KB |
Output is correct |
27 |
Correct |
10 ms |
212 KB |
Output is correct |
28 |
Correct |
12 ms |
212 KB |
Output is correct |
29 |
Correct |
8 ms |
308 KB |
Output is correct |
30 |
Correct |
9 ms |
308 KB |
Output is correct |
31 |
Correct |
12 ms |
308 KB |
Output is correct |
32 |
Correct |
12 ms |
212 KB |
Output is correct |
33 |
Correct |
13 ms |
212 KB |
Output is correct |
34 |
Execution timed out |
2089 ms |
212 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |