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>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define lli long long int
#define debugsl(a) cout << #a << " = " << a << ", "
#define debug(a) cout << #a << " = " << a << endl
lli n,k,ini,fin,res,mitad,letra,cant;
char arr[200002],letras[3];
bool checa(lli m) {
rep(i,1,n-m+1) {
letra = 0;
cant = 0;
rep(j,0,m-1) {
if (arr[j+i] == letras[letra]){
cant++;
if (cant == k) {letra++; cant=0;}
}
if (letra == 3) return true;
}
}
return false;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
rep(i,1,n) cin >> arr[i];
ini = k*3;
fin = n;
res = -1;
letras[0] = 'J';
letras[1] = 'O';
letras[2] = 'I';
while (ini <= fin) {
mitad = (ini+fin) / 2;
if (checa(mitad)){
res = mitad - (k*3);
fin = mitad-1;
}
else ini = mitad + 1;
}
cout << res;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |