#include<bits/stdc++.h>
using namespace std;
#define lalala ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ll long long
#define pb push_back
#define N 17
int n;
int arr[N];
ll int hesap(int nerdeyim,int kac,int lop){
if(lop==5)return 1000000000;
int yes=0;
for(int i=0;i<n-1;i++){
if(arr[i]==arr[i+1]){yes=1;break;}
}
if(yes==0)return kac;
if(nerdeyim>=n-1){
return hesap(0,kac,lop+1);
}
ll int a=1000000000;
ll int b=1000000000;
if(arr[nerdeyim]==arr[nerdeyim+1]){
swap(arr[nerdeyim],arr[nerdeyim+1]);
b=hesap(nerdeyim+1,kac+1,lop);
swap(arr[nerdeyim],arr[nerdeyim+1]);
}
else{
a=hesap(nerdeyim+1,kac,lop);
}
return min(a,b);
}
int main(){
lalala;
cin>>n;
string str;cin>>str;
for(int i=0;i<n;i++){
if(str[i]=='G')arr[i]=1;
if(str[i]=='Y')arr[i]=2;
}
ll int a=hesap(0,0,0);
if(a==1000000000)a=-1;
cout<<a<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |