#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<pair<int, int>, pair<int, int>>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
#define int ll
int N, ST[80005]; string S;
vector<int> A, B;
int solve(int v) {
vector<pair<int, int>> P;
for(int l = 0; l < N; l++)
P.push_back({A[l], B[(l + v) % N]});
int res = 0;
for(int l = 0; l < N; l++) {
for(int i = l + 1; i < N; i++) {
int U = P[l].first, V = P[l].second;
int X = P[i].first, Y = P[i].second;
if(U > V) swap(U, V);
if(X > Y) swap(X, Y);
if(V < X) continue;
if(Y < U) continue;
if(U > X && V < Y) continue;
if(X > U && Y < V) continue;
res++;
}
}
return res;
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> S; int res = 0;
for(int l = 0; l < 2 * N; l++) {
if(S[l] == 'B') A.push_back(l);
if(S[l] == 'W') B.push_back(l);
}
int lo = 0, hi = N - 1;
while(lo <= hi) {
int md = (lo + hi) / 2;
int U = solve(md), V = solve(md + 1);
if(V > U) { lo = md + 1, res = max(res, V); }
else hi = md - 1, res = max(res, U);
}
cout << res << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
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 |
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 |
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 |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
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 |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
3 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
3 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
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 |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
3 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
3 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
352 KB |
Output is correct |
34 |
Correct |
82 ms |
412 KB |
Output is correct |
35 |
Correct |
62 ms |
424 KB |
Output is correct |
36 |
Correct |
72 ms |
424 KB |
Output is correct |
37 |
Correct |
84 ms |
416 KB |
Output is correct |
38 |
Correct |
76 ms |
340 KB |
Output is correct |
39 |
Correct |
68 ms |
416 KB |
Output is correct |
40 |
Correct |
56 ms |
432 KB |
Output is correct |
41 |
Correct |
44 ms |
412 KB |
Output is correct |
42 |
Correct |
63 ms |
420 KB |
Output is correct |
43 |
Correct |
69 ms |
340 KB |
Output is correct |
44 |
Correct |
57 ms |
424 KB |
Output is correct |
45 |
Correct |
57 ms |
340 KB |
Output is correct |
46 |
Correct |
61 ms |
340 KB |
Output is correct |
47 |
Correct |
63 ms |
412 KB |
Output is correct |
48 |
Correct |
66 ms |
340 KB |
Output is correct |
49 |
Correct |
59 ms |
416 KB |
Output is correct |
50 |
Correct |
59 ms |
416 KB |
Output is correct |
51 |
Correct |
54 ms |
340 KB |
Output is correct |
52 |
Correct |
61 ms |
436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
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 |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
3 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
3 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
352 KB |
Output is correct |
34 |
Correct |
82 ms |
412 KB |
Output is correct |
35 |
Correct |
62 ms |
424 KB |
Output is correct |
36 |
Correct |
72 ms |
424 KB |
Output is correct |
37 |
Correct |
84 ms |
416 KB |
Output is correct |
38 |
Correct |
76 ms |
340 KB |
Output is correct |
39 |
Correct |
68 ms |
416 KB |
Output is correct |
40 |
Correct |
56 ms |
432 KB |
Output is correct |
41 |
Correct |
44 ms |
412 KB |
Output is correct |
42 |
Correct |
63 ms |
420 KB |
Output is correct |
43 |
Correct |
69 ms |
340 KB |
Output is correct |
44 |
Correct |
57 ms |
424 KB |
Output is correct |
45 |
Correct |
57 ms |
340 KB |
Output is correct |
46 |
Correct |
61 ms |
340 KB |
Output is correct |
47 |
Correct |
63 ms |
412 KB |
Output is correct |
48 |
Correct |
66 ms |
340 KB |
Output is correct |
49 |
Correct |
59 ms |
416 KB |
Output is correct |
50 |
Correct |
59 ms |
416 KB |
Output is correct |
51 |
Correct |
54 ms |
340 KB |
Output is correct |
52 |
Correct |
61 ms |
436 KB |
Output is correct |
53 |
Execution timed out |
2091 ms |
8468 KB |
Time limit exceeded |
54 |
Halted |
0 ms |
0 KB |
- |