#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define int long long
#define all(x) x.begin(), x.end()
#define endl '\n'
#define x first
#define y second
const int N=200005;
const int INF=1e18;
const int mod=924844033;
struct BIT{
vector<int> v=vector<int>(N);
void add(int p,int t){
for(int i=p;i<N;i+=i&(-i)){
v[i]+=t;
}
}
int ask(int p){
int ans=0;
for(int i=p;i>0;i-=i&(-i)){
ans+=v[i];
}
return ans;
}
};
int32_t main() {
LCBorz;
int n;cin>>n;
string s;cin>>s;
vector<int> a,b;
for(int i=0;i<n<<1;i++){
if(s[i]=='W'){
a.push_back(i+1);
}
else{
b.push_back(i+1);
}
}
auto solve=[&](int k)->int {
vector<pair<int,int>> v(n);
BIT bit;
for(int i=0;i<n;i++){
v[i]=make_pair(a[i],b[(i+k)%n]);
if(v[i].x>v[i].y){
swap(v[i].x,v[i].y);
}
bit.add(v[i].x,1);
bit.add(v[i].y,-1);
}
int ans=0;
sort(all(v));
for(int i=0;i<n;i++){
ans+=bit.ask(v[i].y-1)-bit.ask(v[i].x);
bit.add(v[i].x,-1);
bit.add(v[i].y,2);
}
return ans;
};
int ans=0;
for(int i=0;i<n;i++){
ans=max(ans,solve(i)/2);
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1884 KB |
Output is correct |
3 |
Correct |
1 ms |
1996 KB |
Output is correct |
4 |
Correct |
2 ms |
1880 KB |
Output is correct |
5 |
Correct |
1 ms |
1884 KB |
Output is correct |
6 |
Correct |
2 ms |
2012 KB |
Output is correct |
7 |
Correct |
1 ms |
1884 KB |
Output is correct |
8 |
Correct |
1 ms |
1884 KB |
Output is correct |
9 |
Correct |
2 ms |
1884 KB |
Output is correct |
10 |
Correct |
1 ms |
1884 KB |
Output is correct |
11 |
Correct |
1 ms |
1884 KB |
Output is correct |
12 |
Correct |
1 ms |
1884 KB |
Output is correct |
13 |
Correct |
1 ms |
1884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1884 KB |
Output is correct |
3 |
Correct |
1 ms |
1996 KB |
Output is correct |
4 |
Correct |
2 ms |
1880 KB |
Output is correct |
5 |
Correct |
1 ms |
1884 KB |
Output is correct |
6 |
Correct |
2 ms |
2012 KB |
Output is correct |
7 |
Correct |
1 ms |
1884 KB |
Output is correct |
8 |
Correct |
1 ms |
1884 KB |
Output is correct |
9 |
Correct |
2 ms |
1884 KB |
Output is correct |
10 |
Correct |
1 ms |
1884 KB |
Output is correct |
11 |
Correct |
1 ms |
1884 KB |
Output is correct |
12 |
Correct |
1 ms |
1884 KB |
Output is correct |
13 |
Correct |
1 ms |
1884 KB |
Output is correct |
14 |
Correct |
20 ms |
2060 KB |
Output is correct |
15 |
Correct |
20 ms |
1884 KB |
Output is correct |
16 |
Correct |
19 ms |
1880 KB |
Output is correct |
17 |
Correct |
19 ms |
1880 KB |
Output is correct |
18 |
Correct |
16 ms |
1884 KB |
Output is correct |
19 |
Correct |
19 ms |
1884 KB |
Output is correct |
20 |
Correct |
17 ms |
2056 KB |
Output is correct |
21 |
Correct |
16 ms |
2060 KB |
Output is correct |
22 |
Correct |
16 ms |
1884 KB |
Output is correct |
23 |
Correct |
10 ms |
1884 KB |
Output is correct |
24 |
Correct |
16 ms |
2052 KB |
Output is correct |
25 |
Correct |
15 ms |
1884 KB |
Output is correct |
26 |
Correct |
16 ms |
1884 KB |
Output is correct |
27 |
Correct |
17 ms |
1884 KB |
Output is correct |
28 |
Correct |
23 ms |
2116 KB |
Output is correct |
29 |
Correct |
15 ms |
1884 KB |
Output is correct |
30 |
Correct |
16 ms |
1884 KB |
Output is correct |
31 |
Correct |
19 ms |
1884 KB |
Output is correct |
32 |
Correct |
18 ms |
2052 KB |
Output is correct |
33 |
Correct |
20 ms |
2064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1884 KB |
Output is correct |
3 |
Correct |
1 ms |
1996 KB |
Output is correct |
4 |
Correct |
2 ms |
1880 KB |
Output is correct |
5 |
Correct |
1 ms |
1884 KB |
Output is correct |
6 |
Correct |
2 ms |
2012 KB |
Output is correct |
7 |
Correct |
1 ms |
1884 KB |
Output is correct |
8 |
Correct |
1 ms |
1884 KB |
Output is correct |
9 |
Correct |
2 ms |
1884 KB |
Output is correct |
10 |
Correct |
1 ms |
1884 KB |
Output is correct |
11 |
Correct |
1 ms |
1884 KB |
Output is correct |
12 |
Correct |
1 ms |
1884 KB |
Output is correct |
13 |
Correct |
1 ms |
1884 KB |
Output is correct |
14 |
Correct |
20 ms |
2060 KB |
Output is correct |
15 |
Correct |
20 ms |
1884 KB |
Output is correct |
16 |
Correct |
19 ms |
1880 KB |
Output is correct |
17 |
Correct |
19 ms |
1880 KB |
Output is correct |
18 |
Correct |
16 ms |
1884 KB |
Output is correct |
19 |
Correct |
19 ms |
1884 KB |
Output is correct |
20 |
Correct |
17 ms |
2056 KB |
Output is correct |
21 |
Correct |
16 ms |
2060 KB |
Output is correct |
22 |
Correct |
16 ms |
1884 KB |
Output is correct |
23 |
Correct |
10 ms |
1884 KB |
Output is correct |
24 |
Correct |
16 ms |
2052 KB |
Output is correct |
25 |
Correct |
15 ms |
1884 KB |
Output is correct |
26 |
Correct |
16 ms |
1884 KB |
Output is correct |
27 |
Correct |
17 ms |
1884 KB |
Output is correct |
28 |
Correct |
23 ms |
2116 KB |
Output is correct |
29 |
Correct |
15 ms |
1884 KB |
Output is correct |
30 |
Correct |
16 ms |
1884 KB |
Output is correct |
31 |
Correct |
19 ms |
1884 KB |
Output is correct |
32 |
Correct |
18 ms |
2052 KB |
Output is correct |
33 |
Correct |
20 ms |
2064 KB |
Output is correct |
34 |
Correct |
525 ms |
2340 KB |
Output is correct |
35 |
Correct |
524 ms |
2108 KB |
Output is correct |
36 |
Correct |
503 ms |
2344 KB |
Output is correct |
37 |
Correct |
479 ms |
2344 KB |
Output is correct |
38 |
Correct |
448 ms |
2112 KB |
Output is correct |
39 |
Correct |
482 ms |
2088 KB |
Output is correct |
40 |
Correct |
428 ms |
2108 KB |
Output is correct |
41 |
Correct |
395 ms |
2108 KB |
Output is correct |
42 |
Correct |
515 ms |
2340 KB |
Output is correct |
43 |
Correct |
481 ms |
2108 KB |
Output is correct |
44 |
Correct |
452 ms |
2108 KB |
Output is correct |
45 |
Correct |
518 ms |
2112 KB |
Output is correct |
46 |
Correct |
552 ms |
2108 KB |
Output is correct |
47 |
Correct |
503 ms |
2140 KB |
Output is correct |
48 |
Correct |
474 ms |
2108 KB |
Output is correct |
49 |
Correct |
418 ms |
2108 KB |
Output is correct |
50 |
Correct |
535 ms |
2108 KB |
Output is correct |
51 |
Correct |
485 ms |
2084 KB |
Output is correct |
52 |
Correct |
502 ms |
2112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1880 KB |
Output is correct |
2 |
Correct |
1 ms |
1884 KB |
Output is correct |
3 |
Correct |
1 ms |
1996 KB |
Output is correct |
4 |
Correct |
2 ms |
1880 KB |
Output is correct |
5 |
Correct |
1 ms |
1884 KB |
Output is correct |
6 |
Correct |
2 ms |
2012 KB |
Output is correct |
7 |
Correct |
1 ms |
1884 KB |
Output is correct |
8 |
Correct |
1 ms |
1884 KB |
Output is correct |
9 |
Correct |
2 ms |
1884 KB |
Output is correct |
10 |
Correct |
1 ms |
1884 KB |
Output is correct |
11 |
Correct |
1 ms |
1884 KB |
Output is correct |
12 |
Correct |
1 ms |
1884 KB |
Output is correct |
13 |
Correct |
1 ms |
1884 KB |
Output is correct |
14 |
Correct |
20 ms |
2060 KB |
Output is correct |
15 |
Correct |
20 ms |
1884 KB |
Output is correct |
16 |
Correct |
19 ms |
1880 KB |
Output is correct |
17 |
Correct |
19 ms |
1880 KB |
Output is correct |
18 |
Correct |
16 ms |
1884 KB |
Output is correct |
19 |
Correct |
19 ms |
1884 KB |
Output is correct |
20 |
Correct |
17 ms |
2056 KB |
Output is correct |
21 |
Correct |
16 ms |
2060 KB |
Output is correct |
22 |
Correct |
16 ms |
1884 KB |
Output is correct |
23 |
Correct |
10 ms |
1884 KB |
Output is correct |
24 |
Correct |
16 ms |
2052 KB |
Output is correct |
25 |
Correct |
15 ms |
1884 KB |
Output is correct |
26 |
Correct |
16 ms |
1884 KB |
Output is correct |
27 |
Correct |
17 ms |
1884 KB |
Output is correct |
28 |
Correct |
23 ms |
2116 KB |
Output is correct |
29 |
Correct |
15 ms |
1884 KB |
Output is correct |
30 |
Correct |
16 ms |
1884 KB |
Output is correct |
31 |
Correct |
19 ms |
1884 KB |
Output is correct |
32 |
Correct |
18 ms |
2052 KB |
Output is correct |
33 |
Correct |
20 ms |
2064 KB |
Output is correct |
34 |
Correct |
525 ms |
2340 KB |
Output is correct |
35 |
Correct |
524 ms |
2108 KB |
Output is correct |
36 |
Correct |
503 ms |
2344 KB |
Output is correct |
37 |
Correct |
479 ms |
2344 KB |
Output is correct |
38 |
Correct |
448 ms |
2112 KB |
Output is correct |
39 |
Correct |
482 ms |
2088 KB |
Output is correct |
40 |
Correct |
428 ms |
2108 KB |
Output is correct |
41 |
Correct |
395 ms |
2108 KB |
Output is correct |
42 |
Correct |
515 ms |
2340 KB |
Output is correct |
43 |
Correct |
481 ms |
2108 KB |
Output is correct |
44 |
Correct |
452 ms |
2108 KB |
Output is correct |
45 |
Correct |
518 ms |
2112 KB |
Output is correct |
46 |
Correct |
552 ms |
2108 KB |
Output is correct |
47 |
Correct |
503 ms |
2140 KB |
Output is correct |
48 |
Correct |
474 ms |
2108 KB |
Output is correct |
49 |
Correct |
418 ms |
2108 KB |
Output is correct |
50 |
Correct |
535 ms |
2108 KB |
Output is correct |
51 |
Correct |
485 ms |
2084 KB |
Output is correct |
52 |
Correct |
502 ms |
2112 KB |
Output is correct |
53 |
Runtime error |
49 ms |
17440 KB |
Execution killed with signal 11 |
54 |
Halted |
0 ms |
0 KB |
- |