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<bits/stdc++.h>
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
#define mp make_pair
#define se second
#define fi first
using namespace std;
bool intersect(int l1, int r1, int l2, int r2)
{
if(l1 > r1)
{
swap(l1, r1);
}
if(l2 > r2)
{
swap(l2, r2);
}
if(l1 > l2)
{
swap(l1, l2);
swap(r1, r2);
}
if(r1 > l2 && r1 < r2)
return true;
return false;
}
int main()
{
int n;
cin>>n;
string S;
cin>>S;
vector <int> W, B;
for(int i = 0; i<2*n; i++)
{
if(S.at(i) == 'W')
W.push_back(i);
else
B.push_back(i);
}
int l1, l2, r1, r2, ct = 0, mi = 0;
for(int k = 0; k<n; k++)
{
ct = 0;
for(int i = 0; i<n; i++)
{
for(int j = 0; j<i; j++)
{
l1 = B[i];
l2 = B[j];
r1 = W[(i+k)%n];
r2 = W[(j+k)%n];
if(intersect(l1, r1, l2, r2))
ct++;
}
}
mi = max(ct, mi);
}
cout<<mi<<endl;
}
# | 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... |