This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<cassert>
using namespace std;
int const N = 405;
char a[N];
int main(){
int n;
cin >> n;
int R = 0, G = 0;
for(int i = 0; i < n; i++){
cin >> a[i];
if(a[i] == 'R'){
R++;
}else if(a[i] == 'G') {
G++;
}
assert(a[i] != 'Y');
}
if(R != n / 2 && G != n / 2){
cout << -1 << '\n';
return 0;
}
if(n & 1){
int cnt = 0;
for(int i = 0; i < n; i += 2){
if(R > G){
if(a[i] != 'R'){
cnt++;
}
}else{
if(a[i] != 'G'){
cnt++;
}
}
}
cout << cnt << '\n';
}else{
int cnt1 = 0, cnt2 = 0;
for(int i = 0; i < n; i += 2){
if(a[i] == 'R')
cnt1++;
else{
cnt2++;
}
}
cout << min(cnt1, cnt2) << '\n';
}
}
# | 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... |