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 vector<ll> vl;
int main() {
ios::sync_with_stdio(0);cin.tie(0);
ll n;
cin >> n;
string s;
cin >> s;
vl rem;
for(int i=0;i<n;i++) {
if(s[i] != s[i+n]) {
rem.push_back(0);
} else if(s[i] == 'B') {
rem.push_back(1);
} else {
rem.push_back(-1);
}
}
vl pr;
ll rs = 0;
for(int i=0;i<n;i++) {
pr.push_back(rs);
rs += rem[i];
}
nth_element(pr.begin(),pr.begin()+pr.size()/2,pr.end());
ll piv = -pr[pr.size()/2];
ll tot = n*(n-1)/2;
for(int i=0;i<n;i++) {
tot -= abs(piv);
piv += rem[i];
}
cout << tot << '\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... |