#include <bits/stdc++.h>
using namespace std;
#define int long long
#define nn "\n";
#define pb push_back
#define all(v) (v).begin() , (v).end()
const int N = 2e4+ 4;
int n , T , q , m ;
signed main(){
cin>> n ;
string s ;
cin>> s ;
int ko =0 ;
for(int i=0 ; i < s.size() - 1; i++){
if(s[i]==s[i+1])ko = 1;
}
if(!ko){
cout << 0 ;
return 0 ;
}
queue<pair<string , int >>q;
q.push({s , 0 });
while(q.size()){
string v = q.front().first;
int c = q.front().second;
q.pop();
if(c > n+5)continue;
int ok =0 ;
for(int i=0 ; i < v.size() - 1; i++){
if(v[i]==v[i+1]){
ok = 1;
}
swap(v[i], v[i+1]);
q.push({v , c + 1 });
swap(v[i] , v[i+1]);
}
if(!ok){
cout <<c;
return 0 ;
}
}
cout <<-1 ;
}
Compilation message
joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:14:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for(int i=0 ; i < s.size() - 1; i++){
| ~~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:29:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i=0 ; i < v.size() - 1; i++){
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
1104 KB |
Output is correct |
5 |
Execution timed out |
1129 ms |
978428 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
1104 KB |
Output is correct |
5 |
Execution timed out |
1129 ms |
978428 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
592 KB |
Output is correct |
2 |
Execution timed out |
781 ms |
1048576 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
1104 KB |
Output is correct |
5 |
Execution timed out |
1129 ms |
978428 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |