#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz size()
#define yes "YES"
#define no "NO"
#define IOI ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pf push_front
#define pb push_back
#define S second
#define F first
using namespace std;
const int N = 200 + 5;
const int NN = 1e5;
const int mod = (1e9 + 7);
const int inf = 1e18;
int R, G;
void legenda_ne_umret() {
int n;
cin >> n;
string s, ss;
cin >> s;
ss = s;
for (int i = 0; i < n; i++) {
if (s[i] == 'R') R++;
if (s[i] == 'G') G++;
}
int ans1 = inf, ans = inf;
if(R >= G){
ans = 0;
for(int i = 0 ; i < n ; i++){
if(i % 2 == 0){
for(int j = i; j < n ; j++){
if(s[j] == 'R'){
ans += (j - i);
swap(s[i] , s[j]);
break;
}
}
}
else{
for(int j = i ; j < n ; j++){
if(s[j] == 'G'){
ans += (j - i);
swap(s[i] , s[j]);
break;
}
}
}
}
}
if(G >= R){
ans1 = 0;
s = ss;
for(int i = 0 ; i < n ; i++){
if(i % 2){
for(int j = i ; j < n ; j++){
if(s[j] == 'R'){
ans1 += (j - i);
swap(s[i] , s[j]);
break;
}
}
}
else{
for(int j = i ; j < n ; j++){
if(s[j] == 'G'){
ans1 += (j - i);
swap(s[i] , s[j]);
break;
}
}
}
}
}
cout << min(ans1 , ans);
}
signed main() {
IOI;
// freopen("maze.in", "r", stdin);
// freopen("maze.out", "w", stdout);
/////////////////////////////////////////////
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
// cout << "Case " << i << ":\n";
legenda_ne_umret();
cout << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
456 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |