#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,k,x,y,z;
int val['z'];
char ar[405], tar[405];
int cal() {
int pos[405];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (ar[i] == tar[j]) {
pos[i] = j;
tar[j] = '#';
goto nxt;
}
}
return 1e9;
nxt:;
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++) {
ans += (pos[i] < pos[j]);
}
}
return ans;
}
int main() {
cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> ar[i];
for (int i = 1; i <= n; i++) tar[i] = (i & 1 ? 'R' : 'G');
int ans = cal();
for (int i = 1; i <= n; i++) tar[i] = (i & 1 ? 'G' : 'R');
ans = min(ans,cal());
if (ans > 1e8) cout << "-1\n";
else cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
224 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |