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;
const int N = 2e5 + 10, inf = 1e9;
deque <int> dq[3];
int main()
{
int n, k; cin >> n >> k;
for (int i = 0; i < 3; i++) for (int j = 0; j < k; j++) dq[i].push_back(-inf);
int ans = inf;
for (int i = 0; i < n; i++) {
char c; cin >> c;
if (c == 'J') dq[0].pop_back(), dq[0].push_front(i);
if (c == 'O') dq[1].pop_back(), dq[1].push_front(dq[0].back());
if (c == 'I') dq[2].pop_back(), dq[2].push_front(dq[1].back());
ans = min(ans, i - dq[2][k - 1] + 1);
}
cout << (ans >= inf ? -1 : ans - 3 * k) << "\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... |