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 <iostream>
using namespace std;
const int INF = 1e9;
int taille, niveau;
string mot;
int main() {
cin >> taille >> niveau;
cin >> mot;
int rep = INF;
for(int deb = 0; deb < taille; deb++) {
if(mot[deb] != 'J') {
continue;
}
int curId = deb;
int nbJ = 0;
int total = 0;
while(curId < taille && nbJ < niveau) {
nbJ += (mot[curId++] == 'J');
total++;
}
if(nbJ != niveau) {
continue;
}
int nbO = 0;
while(curId < taille && nbO < niveau) {
nbO += (mot[curId++] == 'O');
total++;
}
if(nbO != niveau) {
continue;
}
int nbI = 0;
while(curId < taille && nbI < niveau) {
nbI += (mot[curId++] == 'I');
total++;
}
if(nbI == niveau) {
rep = min(rep, total - 3 * niveau);
}
}
if(rep == INF) {
cout << "-1";
}
else {
cout << rep;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |