# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
669226 | GrandTiger1729 | JJOOII 2 (JOI20_ho_t2) | C++17 | 1 ms | 320 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
using namespace std;
int val(char c){
if (c == 'J') return 0;
if (c == 'O') return 1;
if (c == 'I') return 2;
}
const int INF = 1e9 + 9;
int main(){
cin.tie(0)->sync_with_stdio(0);
int n, k; cin >> n >> k;
string s; cin >> s;
int l[3]{}, r[3]{}, cnt[3]{};
int ans = INF;
while (r[2] < n){
while (r[0] < n && cnt[0] < k){
if (val(s[r[0]++]) == 0)
cnt[0]++;
}
while (l[1] < r[0]){
if (val(s[l[1]++]) == 1)
cnt[1]--;
}
while (r[1] < n && cnt[1] < k){
if (val(s[r[1]++]) == 1)
cnt[1]++;
}
while (l[2] < r[1]){
if (val(s[l[2]++]) == 2)
cnt[2]--;
}
while (r[2] < n && cnt[2] < k){
if (val(s[r[2]++]) == 2)
cnt[2]++;
}
if (cnt[0] < k || cnt[1] < k || cnt[2] < k) break;
ans = min(ans, r[2] - l[0] - 3 * k);
if (val(s[l[0]++]) == 0)
cnt[0]--;
}
cout << (ans == INF? -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... |