# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1031746 | juicy | JJOOII 2 (JOI20_ho_t2) | C++17 | 5 ms | 5172 KiB |
이 제출은 이전 버전의 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;
int jump[N];
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};
vector<vector<int>> pos(3);
for (int i = n; i >= 1; --i) {
nxt[i] = lst;
int c = conv(s[i - 1]);
lst[c] = i;
pos[c].push_back(i);
if (pos[c].size() >= k) {
jump[i] = pos[c].end()[-k];
} else {
jump[i] = n + 1;
}
}
int ans = 1e9;
for (int i = 0; i < n; ++i) {
if (s[i] == 'J') {
int p = i + 1;
for (int j = 0; j < 3; ++j) {
p = jump[p];
if (p == n + 1) {
break;
}
if (j + 1 < 3) {
p = nxt[p][j + 1];
}
if (p == n + 1) {
break;
}
}
if (p != n + 1) {
ans = min(ans, n - 3 * k - i - n + p);
}
}
}
cout << (ans == 1e9 ? -1 : ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |