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>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = (int) 2e5 + 7;
int n;
string s;
vector<int> a;
vector<int> b;
int f(int l, int r, int x)
{
return (l <= x && x <= r);
}
ll get(int k)
{
vector<pair<int, int>> p;
for (int i = 0; i < n; i++)
{
p.push_back({a[i], b[(i + k) % n]});
}
for (auto &it : p)
{
if (it.second < it.first)
{
swap(it.first, it.second);
}
}
sort(p.begin(), p.end());
ll sol = 0;
for (int i = 0; i < (int) p.size(); i++)
{
for (int j = 0; j < i; j++)
{
sol += (p[i].first <= p[j].second && p[j].second <= p[i].second);
}
}
return sol;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> s;
for (int i = 0; i < 2 * n; i++)
{
if (s[i] == 'W')
{
a.push_back(i);
}
else
{
b.push_back(i);
}
}
ll sol = 0;
for (int k = 0; k < n; k++)
{
sol = max(sol, get(k));
}
cout << sol << "\n";
}
# | 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... |