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;
int main(){
// Input : n - length, k - level, s - string
int n, k;
cin >> n >> k;
std::string s;
cin >> s;
// Target string
std::string opt = "";
for(int i = 0; i < k; i++){
opt += 'J';
}
for(int i = 0; i < k; i++){
opt += 'O';
}
for(int i = 0; i < k; i++){
opt += 'I';
}
int ans = INT_MAX; // since we want the minimum operations, this is max
// so that any min(ans, mismatch) will decrease it
// if it doesnt (at end) we know that the output cant be reached
for (int i = 0; i <= n; i++){
if (s[i] == 'J'){ // j is the character with which opt has to begin
int pointer = 0;
int mismatch = 0;
for (int j = i; j <= n; j++){
if (s[j] == opt[pointer]){ // match
pointer++;
}
else{
mismatch++; // mismatch
}
if (pointer == 3*k){ // end of the string
ans = min(ans, mismatch);
break;
}
}
}
}
if (ans == INT_MAX){ // no min could take place as pointer didnt reach 3k
cout << -1;
}
else{
cout << ans;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |