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
signed main(){
int n, k;
cin >> n >> k;
string s1;
cin >> s1;
string s2 = "";
for (int i = 0; i < k; i++){
s2 += 'J';
}
for (int i = 0; i < k; i++){
s2 += 'O';
}
for (int i = 0; i < k; i++){
s2 += 'I';
}
int ans = INT_MAX;
for (int i = 0; i <= n; i++){
if (s1[i] != 'J'){
continue;
}
else{
int tmp = 0;
int p = 0;
for (int j = i; j < n; j++){
if (p == 3 * k){
ans = min(ans, tmp);
break;
}
else{
if (s1[j] == s2[p]){
p++;
}
else{
tmp += 1;
}
}
}
}
}
if (ans == INT_MAX){
cout << -1 << endl;
}
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... |