/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;
int n;
string s;
void solve(){
cin >> n >> s;
n *= 2;
vector<pii> a;
vector<bool> vis(2*n);
for(int i = 0; i < n/2; ++i){
for(int j = n/2; j < n; ++j){
if(!vis[j] && s[i] != s[j]){
vis[j] = 1;
a.pb({i, j});
break;
}
}
}
int ans = 0;
for(int i = 0; i < n/2; ++i){
// cerr << a[i].ff << ' ' << a[i].ss << '\n';
for(int j=i+1; j < n/2; ++j){
if(a[i].ss >= a[j].ff && a[i].ss <= a[j].ss) ++ans;
}
}
cout << ans;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int tt = 1, aa;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(tt--){
solve();
en;
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
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... |