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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 2e5 + 5;
int n, k;
string s;
array<int, 3> nxt[N];
int conv(char c) {
return c == 'J' ? 0 : (c == 'O' ? 1 : 2);
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> k >> s;
array<int, 3> lst = {n + 1, n + 1, n + 1};
for (int i = n; i >= 1; --i) {
nxt[i] = lst;
lst[conv(s[i - 1])] = i;
}
nxt[0] = lst;
int p = 0;
for (int j = 0; j < 3; ++j) {
for (int i = 0; i < k; ++i) {
p = nxt[p][j];
if (p == n + 1) {
cout << -1;
exit(0);
}
}
}
cout << n - k * 3 - nxt[0][0] + 1 - n + p;
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... |