#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 = 2e5+5;
const int lg = 20;
ll dp[nax];
int n;
vi blck, wht;
ll test(int md){
if(dp[md] != -1) return dp[md];
int res = 0;
for (int j = 0; j < n; ++j)
{
int ind = (j+md)%n;
int a = blck[j], b = wht[ind];
if(a > b) swap(a,b);
int bt = b-a-1;
res += min(bt, 2*n-bt-2);
}
res /= 2;
return dp[md] = res;
}
int main() {
optimise;
cin >> n;
string s;
cin >> s;
memset(dp, -1, sizeof dp);
for (int i = 0; i < n*2; ++i)
{
if(s[i] == 'B') blck.pb(i);
if(s[i] == 'W') wht.pb(i);
}
ll mx = 0;
int l = 0, r = n;
while (l < r)
{
int md = (l+r)/2;
ll a = test(md+1), b = test(md);
if(a > b){
mx = max(mx, a);
l = md+1;
} else {
mx = max(mx, b);
r = md;
}
}
cout << mx << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
2 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
2 ms |
1876 KB |
Output is correct |
7 |
Correct |
1 ms |
1876 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1876 KB |
Output is correct |
11 |
Correct |
2 ms |
1920 KB |
Output is correct |
12 |
Correct |
2 ms |
1876 KB |
Output is correct |
13 |
Correct |
1 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
2 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
2 ms |
1876 KB |
Output is correct |
7 |
Correct |
1 ms |
1876 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1876 KB |
Output is correct |
11 |
Correct |
2 ms |
1920 KB |
Output is correct |
12 |
Correct |
2 ms |
1876 KB |
Output is correct |
13 |
Correct |
1 ms |
1876 KB |
Output is correct |
14 |
Correct |
1 ms |
1876 KB |
Output is correct |
15 |
Correct |
1 ms |
1876 KB |
Output is correct |
16 |
Correct |
2 ms |
1876 KB |
Output is correct |
17 |
Correct |
1 ms |
1876 KB |
Output is correct |
18 |
Correct |
1 ms |
1876 KB |
Output is correct |
19 |
Correct |
1 ms |
1876 KB |
Output is correct |
20 |
Correct |
1 ms |
1876 KB |
Output is correct |
21 |
Correct |
1 ms |
1876 KB |
Output is correct |
22 |
Correct |
1 ms |
1876 KB |
Output is correct |
23 |
Correct |
1 ms |
1876 KB |
Output is correct |
24 |
Correct |
1 ms |
1876 KB |
Output is correct |
25 |
Correct |
1 ms |
1876 KB |
Output is correct |
26 |
Correct |
1 ms |
1876 KB |
Output is correct |
27 |
Correct |
1 ms |
1876 KB |
Output is correct |
28 |
Correct |
2 ms |
1876 KB |
Output is correct |
29 |
Correct |
1 ms |
1876 KB |
Output is correct |
30 |
Correct |
1 ms |
1876 KB |
Output is correct |
31 |
Correct |
1 ms |
1876 KB |
Output is correct |
32 |
Correct |
1 ms |
1876 KB |
Output is correct |
33 |
Correct |
2 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
2 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
2 ms |
1876 KB |
Output is correct |
7 |
Correct |
1 ms |
1876 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1876 KB |
Output is correct |
11 |
Correct |
2 ms |
1920 KB |
Output is correct |
12 |
Correct |
2 ms |
1876 KB |
Output is correct |
13 |
Correct |
1 ms |
1876 KB |
Output is correct |
14 |
Correct |
1 ms |
1876 KB |
Output is correct |
15 |
Correct |
1 ms |
1876 KB |
Output is correct |
16 |
Correct |
2 ms |
1876 KB |
Output is correct |
17 |
Correct |
1 ms |
1876 KB |
Output is correct |
18 |
Correct |
1 ms |
1876 KB |
Output is correct |
19 |
Correct |
1 ms |
1876 KB |
Output is correct |
20 |
Correct |
1 ms |
1876 KB |
Output is correct |
21 |
Correct |
1 ms |
1876 KB |
Output is correct |
22 |
Correct |
1 ms |
1876 KB |
Output is correct |
23 |
Correct |
1 ms |
1876 KB |
Output is correct |
24 |
Correct |
1 ms |
1876 KB |
Output is correct |
25 |
Correct |
1 ms |
1876 KB |
Output is correct |
26 |
Correct |
1 ms |
1876 KB |
Output is correct |
27 |
Correct |
1 ms |
1876 KB |
Output is correct |
28 |
Correct |
2 ms |
1876 KB |
Output is correct |
29 |
Correct |
1 ms |
1876 KB |
Output is correct |
30 |
Correct |
1 ms |
1876 KB |
Output is correct |
31 |
Correct |
1 ms |
1876 KB |
Output is correct |
32 |
Correct |
1 ms |
1876 KB |
Output is correct |
33 |
Correct |
2 ms |
1876 KB |
Output is correct |
34 |
Correct |
2 ms |
1876 KB |
Output is correct |
35 |
Correct |
1 ms |
1876 KB |
Output is correct |
36 |
Correct |
1 ms |
1876 KB |
Output is correct |
37 |
Correct |
1 ms |
1876 KB |
Output is correct |
38 |
Correct |
1 ms |
1876 KB |
Output is correct |
39 |
Correct |
1 ms |
1876 KB |
Output is correct |
40 |
Correct |
1 ms |
1876 KB |
Output is correct |
41 |
Correct |
1 ms |
1876 KB |
Output is correct |
42 |
Correct |
3 ms |
1876 KB |
Output is correct |
43 |
Correct |
1 ms |
1876 KB |
Output is correct |
44 |
Correct |
1 ms |
1876 KB |
Output is correct |
45 |
Correct |
1 ms |
1876 KB |
Output is correct |
46 |
Correct |
1 ms |
1876 KB |
Output is correct |
47 |
Correct |
2 ms |
1876 KB |
Output is correct |
48 |
Correct |
1 ms |
1876 KB |
Output is correct |
49 |
Correct |
1 ms |
1876 KB |
Output is correct |
50 |
Correct |
1 ms |
1876 KB |
Output is correct |
51 |
Correct |
1 ms |
1876 KB |
Output is correct |
52 |
Correct |
1 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
2 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
2 ms |
1876 KB |
Output is correct |
7 |
Correct |
1 ms |
1876 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
1 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1876 KB |
Output is correct |
11 |
Correct |
2 ms |
1920 KB |
Output is correct |
12 |
Correct |
2 ms |
1876 KB |
Output is correct |
13 |
Correct |
1 ms |
1876 KB |
Output is correct |
14 |
Correct |
1 ms |
1876 KB |
Output is correct |
15 |
Correct |
1 ms |
1876 KB |
Output is correct |
16 |
Correct |
2 ms |
1876 KB |
Output is correct |
17 |
Correct |
1 ms |
1876 KB |
Output is correct |
18 |
Correct |
1 ms |
1876 KB |
Output is correct |
19 |
Correct |
1 ms |
1876 KB |
Output is correct |
20 |
Correct |
1 ms |
1876 KB |
Output is correct |
21 |
Correct |
1 ms |
1876 KB |
Output is correct |
22 |
Correct |
1 ms |
1876 KB |
Output is correct |
23 |
Correct |
1 ms |
1876 KB |
Output is correct |
24 |
Correct |
1 ms |
1876 KB |
Output is correct |
25 |
Correct |
1 ms |
1876 KB |
Output is correct |
26 |
Correct |
1 ms |
1876 KB |
Output is correct |
27 |
Correct |
1 ms |
1876 KB |
Output is correct |
28 |
Correct |
2 ms |
1876 KB |
Output is correct |
29 |
Correct |
1 ms |
1876 KB |
Output is correct |
30 |
Correct |
1 ms |
1876 KB |
Output is correct |
31 |
Correct |
1 ms |
1876 KB |
Output is correct |
32 |
Correct |
1 ms |
1876 KB |
Output is correct |
33 |
Correct |
2 ms |
1876 KB |
Output is correct |
34 |
Correct |
2 ms |
1876 KB |
Output is correct |
35 |
Correct |
1 ms |
1876 KB |
Output is correct |
36 |
Correct |
1 ms |
1876 KB |
Output is correct |
37 |
Correct |
1 ms |
1876 KB |
Output is correct |
38 |
Correct |
1 ms |
1876 KB |
Output is correct |
39 |
Correct |
1 ms |
1876 KB |
Output is correct |
40 |
Correct |
1 ms |
1876 KB |
Output is correct |
41 |
Correct |
1 ms |
1876 KB |
Output is correct |
42 |
Correct |
3 ms |
1876 KB |
Output is correct |
43 |
Correct |
1 ms |
1876 KB |
Output is correct |
44 |
Correct |
1 ms |
1876 KB |
Output is correct |
45 |
Correct |
1 ms |
1876 KB |
Output is correct |
46 |
Correct |
1 ms |
1876 KB |
Output is correct |
47 |
Correct |
2 ms |
1876 KB |
Output is correct |
48 |
Correct |
1 ms |
1876 KB |
Output is correct |
49 |
Correct |
1 ms |
1876 KB |
Output is correct |
50 |
Correct |
1 ms |
1876 KB |
Output is correct |
51 |
Correct |
1 ms |
1876 KB |
Output is correct |
52 |
Correct |
1 ms |
1876 KB |
Output is correct |
53 |
Incorrect |
38 ms |
4168 KB |
Output isn't correct |
54 |
Halted |
0 ms |
0 KB |
- |