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;
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;
const int N=200007;
int r[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
string s;
cin>>n>>s;
s='#'+s;
vector<int>Q0,Q1;
for(int i=2*n;i>n;i--)
{
if(s[i]=='B') Q0.pb(i);
else Q1.pb(i);
}
for(int i=1;i<=n;i++)
{
if(s[i]=='B')
{
r[i]=Q1.back();
Q1.pop_back();
}
else
{
r[i]=Q0.back();
Q0.pop_back();
}
}
int ans=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<i;j++)
{
if(r[i]>r[j]) ans++;
}
}
cout<<ans;
return 0;
}
# | 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... |