# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
572603 | groshi | Monochrome Points (JOI20_monochrome) | C++17 | 52 ms | 5764 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<vector>
#include<string>
using namespace std;
#define int long long
vector<int> b,w;
int n;
int wyn(int ile)
{
int wynik=0;
for(int i=0;i<b.size();i++)
{
int l=b[i];
int r=w[(i+ile)%n];
if(l>r)
swap(l,r);
int ile1=(r-l-1);
int ile2=2*n-ile1-2;
wynik+=min(ile1,ile2);
}
return wynik/2;
}
int32_t main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
cin>>n;
string s;
cin>>s;
for(int i=0;i<s.length();i++)
if(s[i]=='B')
b.push_back(i);
else w.push_back(i);
int pocz=0,kon=n,sre,ostd=0;
while(pocz<kon)
{
sre=(pocz+kon)/2;
if(wyn(sre)<wyn(sre+1))
{
ostd=sre+1;
pocz=sre+1;
}
else kon=sre;
}
//for(int i=0;i<n;i++)
//cout<<wyn(i)<<" ";
cout<<wyn(ostd);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |