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 <string>
#include <vector>
#include <algorithm>
using namespace std;
int n, k;
string s;
vector<int> oblicz(char c)
{
vector<int> poz(n + 2);
int prawy = 0, licznik = 0;
for (int lewy = 0; lewy < n; ++lewy)
{
if (lewy > 0 && s[lewy - 1] == c)
licznik--;
while (prawy < n && licznik < k)
{
if (s[prawy] == c)
licznik++;
prawy++;
}
poz[lewy] = (licznik == k ? prawy : n + 1);
}
poz[n] = poz[n + 1] = n + 1;
return poz;
}
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> k >> s;
vector<int> a = oblicz('J');
vector<int> b = oblicz('O');
vector<int> c = oblicz('I');
int odp = n;
for (int i = 0; i < n; ++i)
{
int x = c[b[a[i]]];
if (x <= n)
odp = min(odp, x - i - 3 * k);
}
cout << (odp == n ? -1 : odp) << '\n';
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... |