#include <bits/stdc++.h>
using namespace std;
string s, t;
int n;
int moves;
int solve(){
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(i > 0 && i < n && s[i] == s[i-1] && s[i+1] != s[i]){
swap(s[i], s[i+1]);
moves++;
}
else if(i > 0 && i < n && s[i] == s[i+1] && s[i-1] != s[i]){
swap(s[i], s[i-1]);
moves++;
}
}
}
for(int i = 1; i < n; i++)
if(s[i] == s[i-1]) return - 1;
return moves;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> s;
cout << solve() << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |