#include <bits/stdc++.h>
using namespace std;
#define int long long
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);
#define OYY 1000000005
#define mod 998244353
#define mid (start+end)/2
int32_t main(){
faster
int n;cin>>n;
int r=0,g=0,sr=0,sg=0;
string s;cin>>s;
if(s[0]=='R')sr++;
else if(s[0]=='G')sg++;
for(int i=1;i<n;i++){
if(s[i]=='R')sr++;
else if(s[i]=='G')sg++;
if(s[i]=='R' && s[i-1]=='R'){
r++;
}
else if(s[i]=='G' && s[i-1]=='G'){
g++;
}
}
if(n%2==0){
if(sr==sg){
cout<<max(r,g)<<'\n';
}
else cout<<-1<<'\n';
}
else{
if(sr+1==sg || sr==sg+1){
cout<<max(r,g)<<'\n';
}
else cout<<-1<<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |