#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ss second
#define ff first
#define pb push_back
const int N=3e5+5;
int b[N];
int a[N];
map<string,int>mp;
signed main(){
int n;
cin>>n;
string s;
cin>>s;
mp[s]=1;
queue<string>q;
q.push(s);
while(!q.empty()){
string a=q.front();
q.pop();
for(int i=0;i<n-1;i++){
if(a[i]==a[i+1]){
cout<<mp[a]-1;
return 0;
}
}
for(int i=0;i<n-1;i++){
string b=a;
swap(b[i],b[i+1]);
if(mp[b]==0 ){
mp[b]=mp[a]+1;
q.push(b);
}
}
}
cout<<-1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |