#include<bits/stdc++.h>
using namespace std;
#define cerr if(false) cerr
int main() {
int n; cin >> n;
string s; cin >> s;
long long ans = 0;
for (int i = 0; i < n; i++) {
int j = i + n;
char c = s[i];
if (s[j] == c) continue;
// look for first occurrence of c after i (j?)
int k = i+1;
while (k < 2 * n) {
if (s[k] == c) break;
k++;
}
cerr << c << " : " << j << " <-> " << k << endl;
while (k > j) {
swap(s[k], s[k-1]);
ans++;
k--;
}
}
cout << ans << 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |