#include<bits/stdc++.h>
using namespace std;
int n, i, j, k, a, b;
long long ans=0;
char S[400010];
vector<int>A, B;
int seg[1600010];
void init(){for(int i=0;i<8*n;i++)seg[i]=0;}
void update(int id, int s, int e, int x, int v)
{
if(e<x||x<s)return;
if(s==e)
{
seg[id]+=v;
return;
}
int m=s+e>>1;
update(id*2, s, m, x, v);update(id*2+1, m+1, e, x, v);
seg[id]=seg[id*2]+seg[id*2+1];
}
int get(int id, int s, int e, int l, int r)
{
if(e<l||r<s)return 0;
if(l<=s&&e<=r)return seg[id];
int m=s+e>>1;
return get(id*2, s, m, l, r)+get(id*2+1, m+1, e, l, r);
}
void f(int i)
{
init();
vector<pair<int, int> >V;
for(int j=i;j<n;j++)V.push_back({A[j-i], B[j]});
for(int j=0;j<i;j++)V.push_back({A[j+n-i], B[j]});
for(auto &p:V)if(p.first>p.second)swap(p.first, p.second);
sort(V.begin(), V.end());
long long res=0;
for(auto p:V)
{
int a=p.second;
update(1, 1, 2*n, a, 1);
res+=get(1, 1, 2*n, p.first, a-1);
}
ans=max(ans, res);
}
main()
{
scanf("%d", &n);
scanf("%s", &S);
for(i=0;i<2*n;i++)
{
if(S[i]=='B')A.push_back(i+1);
else B.push_back(i+1);
}
for(i=0;i<n;i++)f(i);
cout<<ans;
}
Compilation message
monochrome.cpp: In function 'void update(int, int, int, int, int)':
monochrome.cpp:17:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
17 | int m=s+e>>1;
| ~^~
monochrome.cpp: In function 'int get(int, int, int, int, int)':
monochrome.cpp:25:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
25 | int m=s+e>>1;
| ~^~
monochrome.cpp: At global scope:
monochrome.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
45 | main()
| ^~~~
monochrome.cpp: In function 'int main()':
monochrome.cpp:48:13: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[400010]' [-Wformat=]
48 | scanf("%s", &S);
| ~^ ~~
| | |
| | char (*)[400010]
| char*
monochrome.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
monochrome.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | scanf("%s", &S);
| ~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
22 ms |
336 KB |
Output is correct |
15 |
Correct |
25 ms |
332 KB |
Output is correct |
16 |
Correct |
23 ms |
332 KB |
Output is correct |
17 |
Correct |
22 ms |
328 KB |
Output is correct |
18 |
Correct |
20 ms |
204 KB |
Output is correct |
19 |
Correct |
21 ms |
324 KB |
Output is correct |
20 |
Correct |
24 ms |
204 KB |
Output is correct |
21 |
Correct |
17 ms |
204 KB |
Output is correct |
22 |
Correct |
17 ms |
332 KB |
Output is correct |
23 |
Correct |
9 ms |
204 KB |
Output is correct |
24 |
Correct |
17 ms |
328 KB |
Output is correct |
25 |
Correct |
19 ms |
320 KB |
Output is correct |
26 |
Correct |
22 ms |
204 KB |
Output is correct |
27 |
Correct |
19 ms |
312 KB |
Output is correct |
28 |
Correct |
21 ms |
328 KB |
Output is correct |
29 |
Correct |
15 ms |
324 KB |
Output is correct |
30 |
Correct |
17 ms |
328 KB |
Output is correct |
31 |
Correct |
29 ms |
308 KB |
Output is correct |
32 |
Correct |
22 ms |
204 KB |
Output is correct |
33 |
Correct |
24 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
22 ms |
336 KB |
Output is correct |
15 |
Correct |
25 ms |
332 KB |
Output is correct |
16 |
Correct |
23 ms |
332 KB |
Output is correct |
17 |
Correct |
22 ms |
328 KB |
Output is correct |
18 |
Correct |
20 ms |
204 KB |
Output is correct |
19 |
Correct |
21 ms |
324 KB |
Output is correct |
20 |
Correct |
24 ms |
204 KB |
Output is correct |
21 |
Correct |
17 ms |
204 KB |
Output is correct |
22 |
Correct |
17 ms |
332 KB |
Output is correct |
23 |
Correct |
9 ms |
204 KB |
Output is correct |
24 |
Correct |
17 ms |
328 KB |
Output is correct |
25 |
Correct |
19 ms |
320 KB |
Output is correct |
26 |
Correct |
22 ms |
204 KB |
Output is correct |
27 |
Correct |
19 ms |
312 KB |
Output is correct |
28 |
Correct |
21 ms |
328 KB |
Output is correct |
29 |
Correct |
15 ms |
324 KB |
Output is correct |
30 |
Correct |
17 ms |
328 KB |
Output is correct |
31 |
Correct |
29 ms |
308 KB |
Output is correct |
32 |
Correct |
22 ms |
204 KB |
Output is correct |
33 |
Correct |
24 ms |
328 KB |
Output is correct |
34 |
Correct |
1291 ms |
404 KB |
Output is correct |
35 |
Correct |
1175 ms |
400 KB |
Output is correct |
36 |
Correct |
1129 ms |
396 KB |
Output is correct |
37 |
Correct |
1064 ms |
400 KB |
Output is correct |
38 |
Correct |
967 ms |
392 KB |
Output is correct |
39 |
Correct |
1079 ms |
400 KB |
Output is correct |
40 |
Correct |
942 ms |
392 KB |
Output is correct |
41 |
Correct |
876 ms |
400 KB |
Output is correct |
42 |
Correct |
1163 ms |
400 KB |
Output is correct |
43 |
Correct |
1154 ms |
396 KB |
Output is correct |
44 |
Correct |
1031 ms |
396 KB |
Output is correct |
45 |
Correct |
1073 ms |
332 KB |
Output is correct |
46 |
Correct |
1105 ms |
396 KB |
Output is correct |
47 |
Correct |
1194 ms |
396 KB |
Output is correct |
48 |
Correct |
1130 ms |
404 KB |
Output is correct |
49 |
Correct |
946 ms |
392 KB |
Output is correct |
50 |
Correct |
1116 ms |
396 KB |
Output is correct |
51 |
Correct |
1111 ms |
396 KB |
Output is correct |
52 |
Correct |
1168 ms |
452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
22 ms |
336 KB |
Output is correct |
15 |
Correct |
25 ms |
332 KB |
Output is correct |
16 |
Correct |
23 ms |
332 KB |
Output is correct |
17 |
Correct |
22 ms |
328 KB |
Output is correct |
18 |
Correct |
20 ms |
204 KB |
Output is correct |
19 |
Correct |
21 ms |
324 KB |
Output is correct |
20 |
Correct |
24 ms |
204 KB |
Output is correct |
21 |
Correct |
17 ms |
204 KB |
Output is correct |
22 |
Correct |
17 ms |
332 KB |
Output is correct |
23 |
Correct |
9 ms |
204 KB |
Output is correct |
24 |
Correct |
17 ms |
328 KB |
Output is correct |
25 |
Correct |
19 ms |
320 KB |
Output is correct |
26 |
Correct |
22 ms |
204 KB |
Output is correct |
27 |
Correct |
19 ms |
312 KB |
Output is correct |
28 |
Correct |
21 ms |
328 KB |
Output is correct |
29 |
Correct |
15 ms |
324 KB |
Output is correct |
30 |
Correct |
17 ms |
328 KB |
Output is correct |
31 |
Correct |
29 ms |
308 KB |
Output is correct |
32 |
Correct |
22 ms |
204 KB |
Output is correct |
33 |
Correct |
24 ms |
328 KB |
Output is correct |
34 |
Correct |
1291 ms |
404 KB |
Output is correct |
35 |
Correct |
1175 ms |
400 KB |
Output is correct |
36 |
Correct |
1129 ms |
396 KB |
Output is correct |
37 |
Correct |
1064 ms |
400 KB |
Output is correct |
38 |
Correct |
967 ms |
392 KB |
Output is correct |
39 |
Correct |
1079 ms |
400 KB |
Output is correct |
40 |
Correct |
942 ms |
392 KB |
Output is correct |
41 |
Correct |
876 ms |
400 KB |
Output is correct |
42 |
Correct |
1163 ms |
400 KB |
Output is correct |
43 |
Correct |
1154 ms |
396 KB |
Output is correct |
44 |
Correct |
1031 ms |
396 KB |
Output is correct |
45 |
Correct |
1073 ms |
332 KB |
Output is correct |
46 |
Correct |
1105 ms |
396 KB |
Output is correct |
47 |
Correct |
1194 ms |
396 KB |
Output is correct |
48 |
Correct |
1130 ms |
404 KB |
Output is correct |
49 |
Correct |
946 ms |
392 KB |
Output is correct |
50 |
Correct |
1116 ms |
396 KB |
Output is correct |
51 |
Correct |
1111 ms |
396 KB |
Output is correct |
52 |
Correct |
1168 ms |
452 KB |
Output is correct |
53 |
Execution timed out |
2080 ms |
12252 KB |
Time limit exceeded |
54 |
Halted |
0 ms |
0 KB |
- |