#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |