#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 2e9+5
#define eps 1e-7
#define eps1 1e-25
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
#define V 450
using namespace std;
const int MOD = 1e9;
const int nax = 2e3+5;
const int lg = 20;
int st[nax*8];
void update(int v, int l, int r, int pos, int val){
if(pos > r || pos < l) return;
if(l == r){
st[v] += val;
return;
}
int md = (l+r)/2;
update(v*2, l, md, pos, val);
update(v*2+1, md+1, r, pos, val);
st[v] = st[v*2]+st[v*2+1];
}
int query(int v, int l, int r, int i, int j){
if(i > r || j < l) return 0;
if(i <= l && r <= j) return st[v];
int md = (l+r)/2;
return query(v*2, l, md, i, j)+ query(v*2+1, md+1, r, i, j);
}
int main() {
optimise;
int n;
cin >> n;
string s;
cin >> s;
vi blck, wht;
for (int i = 0; i < n*2; ++i)
{
if(s[i] == 'B') blck.pb(i);
if(s[i] == 'W') wht.pb(i);
}
int mx = 0;
for (int i = 0; i < n; ++i)
{
int res = 0;
memset(st, 0, sizeof st);
vii qr;
for (int j = 0; j < n; ++j)
{
int ind = (j+i)%n;
int a = blck[j], b = wht[ind];
if(a > b) swap(a,b);
qr.pb({a,b});
}
sort(qr.begin(), qr.end());
reverse(qr.begin(), qr.end());
for(auto x : qr){
res += query(1,0,2*n-1, x.fi, x.se);
update(1,0,2*n-1, x.fi, 1);
update(1,0,2*n-1, x.se, -1);
}
mx = max(res, mx);
}
cout << mx << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
35 ms |
384 KB |
Output is correct |
15 |
Correct |
34 ms |
340 KB |
Output is correct |
16 |
Correct |
33 ms |
340 KB |
Output is correct |
17 |
Correct |
32 ms |
340 KB |
Output is correct |
18 |
Correct |
24 ms |
392 KB |
Output is correct |
19 |
Correct |
26 ms |
400 KB |
Output is correct |
20 |
Correct |
27 ms |
468 KB |
Output is correct |
21 |
Correct |
23 ms |
340 KB |
Output is correct |
22 |
Correct |
27 ms |
340 KB |
Output is correct |
23 |
Correct |
13 ms |
340 KB |
Output is correct |
24 |
Correct |
24 ms |
340 KB |
Output is correct |
25 |
Correct |
22 ms |
388 KB |
Output is correct |
26 |
Correct |
25 ms |
392 KB |
Output is correct |
27 |
Correct |
30 ms |
392 KB |
Output is correct |
28 |
Correct |
30 ms |
372 KB |
Output is correct |
29 |
Correct |
25 ms |
340 KB |
Output is correct |
30 |
Correct |
22 ms |
392 KB |
Output is correct |
31 |
Correct |
29 ms |
376 KB |
Output is correct |
32 |
Correct |
32 ms |
384 KB |
Output is correct |
33 |
Correct |
31 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
35 ms |
384 KB |
Output is correct |
15 |
Correct |
34 ms |
340 KB |
Output is correct |
16 |
Correct |
33 ms |
340 KB |
Output is correct |
17 |
Correct |
32 ms |
340 KB |
Output is correct |
18 |
Correct |
24 ms |
392 KB |
Output is correct |
19 |
Correct |
26 ms |
400 KB |
Output is correct |
20 |
Correct |
27 ms |
468 KB |
Output is correct |
21 |
Correct |
23 ms |
340 KB |
Output is correct |
22 |
Correct |
27 ms |
340 KB |
Output is correct |
23 |
Correct |
13 ms |
340 KB |
Output is correct |
24 |
Correct |
24 ms |
340 KB |
Output is correct |
25 |
Correct |
22 ms |
388 KB |
Output is correct |
26 |
Correct |
25 ms |
392 KB |
Output is correct |
27 |
Correct |
30 ms |
392 KB |
Output is correct |
28 |
Correct |
30 ms |
372 KB |
Output is correct |
29 |
Correct |
25 ms |
340 KB |
Output is correct |
30 |
Correct |
22 ms |
392 KB |
Output is correct |
31 |
Correct |
29 ms |
376 KB |
Output is correct |
32 |
Correct |
32 ms |
384 KB |
Output is correct |
33 |
Correct |
31 ms |
340 KB |
Output is correct |
34 |
Correct |
1665 ms |
416 KB |
Output is correct |
35 |
Correct |
1798 ms |
424 KB |
Output is correct |
36 |
Correct |
1623 ms |
424 KB |
Output is correct |
37 |
Correct |
1501 ms |
424 KB |
Output is correct |
38 |
Correct |
1419 ms |
428 KB |
Output is correct |
39 |
Correct |
1595 ms |
424 KB |
Output is correct |
40 |
Correct |
1345 ms |
420 KB |
Output is correct |
41 |
Correct |
1349 ms |
432 KB |
Output is correct |
42 |
Correct |
1637 ms |
424 KB |
Output is correct |
43 |
Correct |
1801 ms |
416 KB |
Output is correct |
44 |
Correct |
1552 ms |
340 KB |
Output is correct |
45 |
Correct |
1468 ms |
420 KB |
Output is correct |
46 |
Correct |
1608 ms |
420 KB |
Output is correct |
47 |
Correct |
1667 ms |
416 KB |
Output is correct |
48 |
Correct |
1643 ms |
420 KB |
Output is correct |
49 |
Correct |
1386 ms |
420 KB |
Output is correct |
50 |
Correct |
1569 ms |
420 KB |
Output is correct |
51 |
Correct |
1666 ms |
416 KB |
Output is correct |
52 |
Correct |
1733 ms |
428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
35 ms |
384 KB |
Output is correct |
15 |
Correct |
34 ms |
340 KB |
Output is correct |
16 |
Correct |
33 ms |
340 KB |
Output is correct |
17 |
Correct |
32 ms |
340 KB |
Output is correct |
18 |
Correct |
24 ms |
392 KB |
Output is correct |
19 |
Correct |
26 ms |
400 KB |
Output is correct |
20 |
Correct |
27 ms |
468 KB |
Output is correct |
21 |
Correct |
23 ms |
340 KB |
Output is correct |
22 |
Correct |
27 ms |
340 KB |
Output is correct |
23 |
Correct |
13 ms |
340 KB |
Output is correct |
24 |
Correct |
24 ms |
340 KB |
Output is correct |
25 |
Correct |
22 ms |
388 KB |
Output is correct |
26 |
Correct |
25 ms |
392 KB |
Output is correct |
27 |
Correct |
30 ms |
392 KB |
Output is correct |
28 |
Correct |
30 ms |
372 KB |
Output is correct |
29 |
Correct |
25 ms |
340 KB |
Output is correct |
30 |
Correct |
22 ms |
392 KB |
Output is correct |
31 |
Correct |
29 ms |
376 KB |
Output is correct |
32 |
Correct |
32 ms |
384 KB |
Output is correct |
33 |
Correct |
31 ms |
340 KB |
Output is correct |
34 |
Correct |
1665 ms |
416 KB |
Output is correct |
35 |
Correct |
1798 ms |
424 KB |
Output is correct |
36 |
Correct |
1623 ms |
424 KB |
Output is correct |
37 |
Correct |
1501 ms |
424 KB |
Output is correct |
38 |
Correct |
1419 ms |
428 KB |
Output is correct |
39 |
Correct |
1595 ms |
424 KB |
Output is correct |
40 |
Correct |
1345 ms |
420 KB |
Output is correct |
41 |
Correct |
1349 ms |
432 KB |
Output is correct |
42 |
Correct |
1637 ms |
424 KB |
Output is correct |
43 |
Correct |
1801 ms |
416 KB |
Output is correct |
44 |
Correct |
1552 ms |
340 KB |
Output is correct |
45 |
Correct |
1468 ms |
420 KB |
Output is correct |
46 |
Correct |
1608 ms |
420 KB |
Output is correct |
47 |
Correct |
1667 ms |
416 KB |
Output is correct |
48 |
Correct |
1643 ms |
420 KB |
Output is correct |
49 |
Correct |
1386 ms |
420 KB |
Output is correct |
50 |
Correct |
1569 ms |
420 KB |
Output is correct |
51 |
Correct |
1666 ms |
416 KB |
Output is correct |
52 |
Correct |
1733 ms |
428 KB |
Output is correct |
53 |
Runtime error |
24 ms |
8316 KB |
Execution killed with signal 11 |
54 |
Halted |
0 ms |
0 KB |
- |