#include <bits/stdc++.h>
using namespace std;
const int N = (int)4e3+10;
string s; int n, ans, tot, fen[N], st[N];
void upd(int x, int v){ for(; x<N; x+=x&-x) fen[x]+=v; }
int sum(int x){ int s=0; for(; x>0; x-=x&-x)s+=fen[x]; return s; }
int sum(int a, int b){ return (a<=b)*(sum(b)-sum(a-1)); }
int main()
{
cin >> n >> s; vector<int> v[2]; if(n>2000) {cout<<0;return 0;}
for(int i = 0; i < 2*n; i++) v[s[i]>'B'].push_back(i+1);
for(int k = 0; k < n; k++){ tot=0;
for(int i = 0; i < n; i++){
int a = v[0][i], b = v[1][(i+k)%n];
if(a>b) swap(a,b); st[a] = a; st[b]=a;
}
for(int i = 1; i <= 2*n; i++){
if(st[i]==i) upd(st[i],1);
else tot+=sum(st[i]+1,i), upd(st[i],-1);
}
ans = max(ans, tot);
}
cout << ans;
}
Compilation message
monochrome.cpp: In function 'int main()':
monochrome.cpp:16:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
16 | if(a>b) swap(a,b); st[a] = a; st[b]=a;
| ^~
monochrome.cpp:16:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
16 | if(a>b) swap(a,b); st[a] = a; st[b]=a;
| ^~
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
260 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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
260 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 |
4 ms |
212 KB |
Output is correct |
15 |
Correct |
4 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
212 KB |
Output is correct |
17 |
Correct |
4 ms |
212 KB |
Output is correct |
18 |
Correct |
3 ms |
212 KB |
Output is correct |
19 |
Correct |
3 ms |
324 KB |
Output is correct |
20 |
Correct |
3 ms |
212 KB |
Output is correct |
21 |
Correct |
4 ms |
212 KB |
Output is correct |
22 |
Correct |
3 ms |
212 KB |
Output is correct |
23 |
Correct |
2 ms |
212 KB |
Output is correct |
24 |
Correct |
3 ms |
212 KB |
Output is correct |
25 |
Correct |
3 ms |
212 KB |
Output is correct |
26 |
Correct |
3 ms |
212 KB |
Output is correct |
27 |
Correct |
3 ms |
320 KB |
Output is correct |
28 |
Correct |
3 ms |
212 KB |
Output is correct |
29 |
Correct |
3 ms |
212 KB |
Output is correct |
30 |
Correct |
3 ms |
212 KB |
Output is correct |
31 |
Correct |
3 ms |
212 KB |
Output is correct |
32 |
Correct |
3 ms |
212 KB |
Output is correct |
33 |
Correct |
3 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
260 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 |
4 ms |
212 KB |
Output is correct |
15 |
Correct |
4 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
212 KB |
Output is correct |
17 |
Correct |
4 ms |
212 KB |
Output is correct |
18 |
Correct |
3 ms |
212 KB |
Output is correct |
19 |
Correct |
3 ms |
324 KB |
Output is correct |
20 |
Correct |
3 ms |
212 KB |
Output is correct |
21 |
Correct |
4 ms |
212 KB |
Output is correct |
22 |
Correct |
3 ms |
212 KB |
Output is correct |
23 |
Correct |
2 ms |
212 KB |
Output is correct |
24 |
Correct |
3 ms |
212 KB |
Output is correct |
25 |
Correct |
3 ms |
212 KB |
Output is correct |
26 |
Correct |
3 ms |
212 KB |
Output is correct |
27 |
Correct |
3 ms |
320 KB |
Output is correct |
28 |
Correct |
3 ms |
212 KB |
Output is correct |
29 |
Correct |
3 ms |
212 KB |
Output is correct |
30 |
Correct |
3 ms |
212 KB |
Output is correct |
31 |
Correct |
3 ms |
212 KB |
Output is correct |
32 |
Correct |
3 ms |
212 KB |
Output is correct |
33 |
Correct |
3 ms |
212 KB |
Output is correct |
34 |
Correct |
186 ms |
356 KB |
Output is correct |
35 |
Correct |
195 ms |
340 KB |
Output is correct |
36 |
Correct |
173 ms |
340 KB |
Output is correct |
37 |
Correct |
162 ms |
340 KB |
Output is correct |
38 |
Correct |
107 ms |
340 KB |
Output is correct |
39 |
Correct |
128 ms |
360 KB |
Output is correct |
40 |
Correct |
114 ms |
340 KB |
Output is correct |
41 |
Correct |
112 ms |
340 KB |
Output is correct |
42 |
Correct |
171 ms |
340 KB |
Output is correct |
43 |
Correct |
142 ms |
344 KB |
Output is correct |
44 |
Correct |
130 ms |
344 KB |
Output is correct |
45 |
Correct |
130 ms |
340 KB |
Output is correct |
46 |
Correct |
140 ms |
344 KB |
Output is correct |
47 |
Correct |
142 ms |
340 KB |
Output is correct |
48 |
Correct |
130 ms |
364 KB |
Output is correct |
49 |
Correct |
102 ms |
344 KB |
Output is correct |
50 |
Correct |
125 ms |
340 KB |
Output is correct |
51 |
Correct |
137 ms |
340 KB |
Output is correct |
52 |
Correct |
131 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
260 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 |
4 ms |
212 KB |
Output is correct |
15 |
Correct |
4 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
212 KB |
Output is correct |
17 |
Correct |
4 ms |
212 KB |
Output is correct |
18 |
Correct |
3 ms |
212 KB |
Output is correct |
19 |
Correct |
3 ms |
324 KB |
Output is correct |
20 |
Correct |
3 ms |
212 KB |
Output is correct |
21 |
Correct |
4 ms |
212 KB |
Output is correct |
22 |
Correct |
3 ms |
212 KB |
Output is correct |
23 |
Correct |
2 ms |
212 KB |
Output is correct |
24 |
Correct |
3 ms |
212 KB |
Output is correct |
25 |
Correct |
3 ms |
212 KB |
Output is correct |
26 |
Correct |
3 ms |
212 KB |
Output is correct |
27 |
Correct |
3 ms |
320 KB |
Output is correct |
28 |
Correct |
3 ms |
212 KB |
Output is correct |
29 |
Correct |
3 ms |
212 KB |
Output is correct |
30 |
Correct |
3 ms |
212 KB |
Output is correct |
31 |
Correct |
3 ms |
212 KB |
Output is correct |
32 |
Correct |
3 ms |
212 KB |
Output is correct |
33 |
Correct |
3 ms |
212 KB |
Output is correct |
34 |
Correct |
186 ms |
356 KB |
Output is correct |
35 |
Correct |
195 ms |
340 KB |
Output is correct |
36 |
Correct |
173 ms |
340 KB |
Output is correct |
37 |
Correct |
162 ms |
340 KB |
Output is correct |
38 |
Correct |
107 ms |
340 KB |
Output is correct |
39 |
Correct |
128 ms |
360 KB |
Output is correct |
40 |
Correct |
114 ms |
340 KB |
Output is correct |
41 |
Correct |
112 ms |
340 KB |
Output is correct |
42 |
Correct |
171 ms |
340 KB |
Output is correct |
43 |
Correct |
142 ms |
344 KB |
Output is correct |
44 |
Correct |
130 ms |
344 KB |
Output is correct |
45 |
Correct |
130 ms |
340 KB |
Output is correct |
46 |
Correct |
140 ms |
344 KB |
Output is correct |
47 |
Correct |
142 ms |
340 KB |
Output is correct |
48 |
Correct |
130 ms |
364 KB |
Output is correct |
49 |
Correct |
102 ms |
344 KB |
Output is correct |
50 |
Correct |
125 ms |
340 KB |
Output is correct |
51 |
Correct |
137 ms |
340 KB |
Output is correct |
52 |
Correct |
131 ms |
340 KB |
Output is correct |
53 |
Incorrect |
6 ms |
868 KB |
Output isn't correct |
54 |
Halted |
0 ms |
0 KB |
- |