#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl "\n"
llo mod=1000000007;
int n;
int it[401];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
//setIO("");
cin>>n;
char ss;
int co=0;
for(int i=0;i<n;i++){
cin>>ss;
if(ss=='R'){
co+=1;
}
else if(ss=='G'){
it[i]=1;
}
else{
return 0;
}
}
if(co>(n+1)/2){
cout<<-1<<endl;
return 0;
}
if(n%2==1){
int ans=0;
int ind=0;
int ind2=0;
for(int i=0;i<n;i++){
if(it[i]==0){
ans+=abs((ind*2+1-co%2)-i);
ind+=1;
}
else{
ans+=abs((ind2*2+co%2)-i);
ind2+=1;
}
}
cout<<ans/2<<endl;
}
else{
int ans=0;
int ind=0;
int ind2=0;
for(int i=0;i<n;i++){
if(it[i]==0){
ans+=abs((ind*2)-i);
ind+=1;
}
else{
ans+=abs((ind2*2+1)-i);
ind2+=1;
}
}
int ans2=0;
ind=0;
ind2=0;
for(int i=0;i<n;i++){
if(it[i]==0){
ans2+=abs((ind*2+1)-i);
ind+=1;
}
else{
ans2+=abs((ind2*2)-i);
ind2+=1;
}
}
cout<<min(ans,ans2)/2<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |