# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
572600 | groshi | Monochrome Points (JOI20_monochrome) | C++17 | 1 ms | 332 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;
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;
}
int 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;
while(pocz<kon)
{
sre=(pocz+kon)/2;
if(wyn(sre)<wyn(sre+1))
{
ostd=sre+1;
pocz=sre+1;
}
else kon=sre;
}
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... |