# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1107333 | vjudge1 | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++17 | 1129 ms | 1048576 KiB |
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 <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 (stderr)
# | 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... |