# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
208924 | eriksuenderhauf | JJOOII 2 (JOI20_ho_t2) | C++11 | 14 ms | 3704 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
#define sz(x) (int)(x).size()
#define trav(x, a) for (const auto& x: a)
#define pii pair<int,int>
#define st first
#define nd second
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
char s[N];
int nx[N][3];
int main() {
int n, k; scanf("%d %d", &n, &k);
scanf("%s", s);
for (int i = 0; i < 3; i++)
nx[n+1][i] = nx[n][i] = n+1;
deque<int> pq[3];
for (int i = n-1; ~i; i--) {
if (s[i] == 'I')
pq[2].push_front(i);
if (s[i] == 'O')
pq[1].push_front(i);
if (s[i] == 'J')
pq[0].push_front(i);
for (int j = 0; j < 3; j++) {
nx[i][j] = nx[i+1][j];
while (sz(pq[j]) > k)
pq[j].pop_back();
if (sz(pq[j]) == k)
nx[i][j] = pq[j].back() + 1;
}
}
int ans = 2*N;
for (int i = 0; i < n; i++) {
if (nx[nx[nx[i][0]][1]][2] > n)
continue;
ans = min(ans, nx[nx[nx[i][0]][1]][2] - i - 3*k);
}
if (ans == 2*N)
ans = -1;
printf("%d\n", ans);
}
컴파일 시 표준 에러 (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... |