이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |