#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MottoHayaku ios::sync_with_stdio(false);cin.tie(0);
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define F first
#define S second
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N=4e5+5;
struct BIT
{
int a[N];
void init()
{
rep1(i,N-1) a[i]=0;
}
void upd(int x,int val)
{
for(;x<N;x+=x&-x) a[x]+=val;
}
int qry(int x)
{
int ret=0;
for(;x;x-=x&-x) ret+=a[x];
return ret;
}
} bit;
int n,to[N];
vector<int> a,b;
string s;
int getans(int i)
{
i=(i%n+n)%n;
rep(j,n)
{
to[a[j]]=b[(j+i)%n];
to[b[(j+i)%n]]=a[j];
}
bit.init();
int tot=0;
rep1(j,n*2)
{
if(to[j]<j) bit.upd(j,-1);
else
{
tot+=bit.qry(to[j]);
bit.upd(to[j],1);
}
}
return tot;
}
signed main()
{
MottoHayaku
cin>>n>>s;
//rep(i,n) s+="BW";
//shuffle(s.begin(),s.end(),rng);
//cout<<n<<"\n"<<s<<"\n";
rep(i,n*2)
{
if(s[i]=='B') a.pb(i+1);
else b.pb(i+1);
}
int l=rng()%n;
int r=l+n-1;
while(l<r)
{
int mid=l+r+1>>1;
int x=getans(mid)-getans(mid-1);
if(x>0) l=mid;
else r=mid-1;
}
cout<<getans(l)<<"\n";
}
Compilation message
monochrome.cpp: In function 'int main()':
monochrome.cpp:76:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
76 | int mid=l+r+1>>1;
| ~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1872 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
1 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
2 ms |
1876 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
2 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1872 KB |
Output is correct |
11 |
Correct |
1 ms |
1876 KB |
Output is correct |
12 |
Correct |
1 ms |
1864 KB |
Output is correct |
13 |
Correct |
2 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1872 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
1 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
2 ms |
1876 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
2 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1872 KB |
Output is correct |
11 |
Correct |
1 ms |
1876 KB |
Output is correct |
12 |
Correct |
1 ms |
1864 KB |
Output is correct |
13 |
Correct |
2 ms |
1876 KB |
Output is correct |
14 |
Correct |
2 ms |
1876 KB |
Output is correct |
15 |
Correct |
2 ms |
1872 KB |
Output is correct |
16 |
Correct |
2 ms |
1876 KB |
Output is correct |
17 |
Correct |
2 ms |
1876 KB |
Output is correct |
18 |
Correct |
2 ms |
1876 KB |
Output is correct |
19 |
Correct |
2 ms |
1876 KB |
Output is correct |
20 |
Correct |
2 ms |
1876 KB |
Output is correct |
21 |
Correct |
2 ms |
1868 KB |
Output is correct |
22 |
Correct |
2 ms |
1876 KB |
Output is correct |
23 |
Correct |
2 ms |
1876 KB |
Output is correct |
24 |
Correct |
3 ms |
1876 KB |
Output is correct |
25 |
Correct |
2 ms |
2000 KB |
Output is correct |
26 |
Correct |
2 ms |
1876 KB |
Output is correct |
27 |
Correct |
2 ms |
1876 KB |
Output is correct |
28 |
Correct |
2 ms |
1876 KB |
Output is correct |
29 |
Correct |
2 ms |
1872 KB |
Output is correct |
30 |
Correct |
2 ms |
1876 KB |
Output is correct |
31 |
Correct |
3 ms |
1876 KB |
Output is correct |
32 |
Correct |
2 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 |
1872 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
1 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
2 ms |
1876 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
2 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1872 KB |
Output is correct |
11 |
Correct |
1 ms |
1876 KB |
Output is correct |
12 |
Correct |
1 ms |
1864 KB |
Output is correct |
13 |
Correct |
2 ms |
1876 KB |
Output is correct |
14 |
Correct |
2 ms |
1876 KB |
Output is correct |
15 |
Correct |
2 ms |
1872 KB |
Output is correct |
16 |
Correct |
2 ms |
1876 KB |
Output is correct |
17 |
Correct |
2 ms |
1876 KB |
Output is correct |
18 |
Correct |
2 ms |
1876 KB |
Output is correct |
19 |
Correct |
2 ms |
1876 KB |
Output is correct |
20 |
Correct |
2 ms |
1876 KB |
Output is correct |
21 |
Correct |
2 ms |
1868 KB |
Output is correct |
22 |
Correct |
2 ms |
1876 KB |
Output is correct |
23 |
Correct |
2 ms |
1876 KB |
Output is correct |
24 |
Correct |
3 ms |
1876 KB |
Output is correct |
25 |
Correct |
2 ms |
2000 KB |
Output is correct |
26 |
Correct |
2 ms |
1876 KB |
Output is correct |
27 |
Correct |
2 ms |
1876 KB |
Output is correct |
28 |
Correct |
2 ms |
1876 KB |
Output is correct |
29 |
Correct |
2 ms |
1872 KB |
Output is correct |
30 |
Correct |
2 ms |
1876 KB |
Output is correct |
31 |
Correct |
3 ms |
1876 KB |
Output is correct |
32 |
Correct |
2 ms |
1876 KB |
Output is correct |
33 |
Correct |
2 ms |
1876 KB |
Output is correct |
34 |
Correct |
7 ms |
1872 KB |
Output is correct |
35 |
Correct |
5 ms |
1872 KB |
Output is correct |
36 |
Correct |
5 ms |
1948 KB |
Output is correct |
37 |
Correct |
5 ms |
1872 KB |
Output is correct |
38 |
Correct |
4 ms |
1876 KB |
Output is correct |
39 |
Correct |
4 ms |
1876 KB |
Output is correct |
40 |
Correct |
5 ms |
1876 KB |
Output is correct |
41 |
Correct |
5 ms |
1876 KB |
Output is correct |
42 |
Correct |
5 ms |
1876 KB |
Output is correct |
43 |
Correct |
4 ms |
1876 KB |
Output is correct |
44 |
Correct |
5 ms |
1872 KB |
Output is correct |
45 |
Correct |
4 ms |
1876 KB |
Output is correct |
46 |
Correct |
5 ms |
1876 KB |
Output is correct |
47 |
Correct |
5 ms |
1876 KB |
Output is correct |
48 |
Correct |
5 ms |
1876 KB |
Output is correct |
49 |
Correct |
4 ms |
1876 KB |
Output is correct |
50 |
Correct |
5 ms |
1876 KB |
Output is correct |
51 |
Correct |
7 ms |
1876 KB |
Output is correct |
52 |
Correct |
6 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1872 KB |
Output is correct |
2 |
Correct |
1 ms |
1876 KB |
Output is correct |
3 |
Correct |
1 ms |
1876 KB |
Output is correct |
4 |
Correct |
1 ms |
1876 KB |
Output is correct |
5 |
Correct |
1 ms |
1876 KB |
Output is correct |
6 |
Correct |
1 ms |
1876 KB |
Output is correct |
7 |
Correct |
2 ms |
1876 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
2 ms |
1876 KB |
Output is correct |
10 |
Correct |
1 ms |
1872 KB |
Output is correct |
11 |
Correct |
1 ms |
1876 KB |
Output is correct |
12 |
Correct |
1 ms |
1864 KB |
Output is correct |
13 |
Correct |
2 ms |
1876 KB |
Output is correct |
14 |
Correct |
2 ms |
1876 KB |
Output is correct |
15 |
Correct |
2 ms |
1872 KB |
Output is correct |
16 |
Correct |
2 ms |
1876 KB |
Output is correct |
17 |
Correct |
2 ms |
1876 KB |
Output is correct |
18 |
Correct |
2 ms |
1876 KB |
Output is correct |
19 |
Correct |
2 ms |
1876 KB |
Output is correct |
20 |
Correct |
2 ms |
1876 KB |
Output is correct |
21 |
Correct |
2 ms |
1868 KB |
Output is correct |
22 |
Correct |
2 ms |
1876 KB |
Output is correct |
23 |
Correct |
2 ms |
1876 KB |
Output is correct |
24 |
Correct |
3 ms |
1876 KB |
Output is correct |
25 |
Correct |
2 ms |
2000 KB |
Output is correct |
26 |
Correct |
2 ms |
1876 KB |
Output is correct |
27 |
Correct |
2 ms |
1876 KB |
Output is correct |
28 |
Correct |
2 ms |
1876 KB |
Output is correct |
29 |
Correct |
2 ms |
1872 KB |
Output is correct |
30 |
Correct |
2 ms |
1876 KB |
Output is correct |
31 |
Correct |
3 ms |
1876 KB |
Output is correct |
32 |
Correct |
2 ms |
1876 KB |
Output is correct |
33 |
Correct |
2 ms |
1876 KB |
Output is correct |
34 |
Correct |
7 ms |
1872 KB |
Output is correct |
35 |
Correct |
5 ms |
1872 KB |
Output is correct |
36 |
Correct |
5 ms |
1948 KB |
Output is correct |
37 |
Correct |
5 ms |
1872 KB |
Output is correct |
38 |
Correct |
4 ms |
1876 KB |
Output is correct |
39 |
Correct |
4 ms |
1876 KB |
Output is correct |
40 |
Correct |
5 ms |
1876 KB |
Output is correct |
41 |
Correct |
5 ms |
1876 KB |
Output is correct |
42 |
Correct |
5 ms |
1876 KB |
Output is correct |
43 |
Correct |
4 ms |
1876 KB |
Output is correct |
44 |
Correct |
5 ms |
1872 KB |
Output is correct |
45 |
Correct |
4 ms |
1876 KB |
Output is correct |
46 |
Correct |
5 ms |
1876 KB |
Output is correct |
47 |
Correct |
5 ms |
1876 KB |
Output is correct |
48 |
Correct |
5 ms |
1876 KB |
Output is correct |
49 |
Correct |
4 ms |
1876 KB |
Output is correct |
50 |
Correct |
5 ms |
1876 KB |
Output is correct |
51 |
Correct |
7 ms |
1876 KB |
Output is correct |
52 |
Correct |
6 ms |
1876 KB |
Output is correct |
53 |
Incorrect |
389 ms |
6108 KB |
Output isn't correct |
54 |
Halted |
0 ms |
0 KB |
- |