# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
201408 | karma | JJOOII 2 (JOI20_ho_t2) | C++14 | 16 ms | 2948 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb emplace_back
#define ll long long
#define fi first
#define se second
#define mp make_pair
//#define int int64_t
using namespace std;
const int N = int(2e5) + 5;
typedef pair<int, int> pii;
string s;
int n, k, jump[N][3], cnt;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define Task "test"
if(fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout);
}
cin >> n >> k >> s;
for(int i = 0, j = -1; i < n; ++i) {
while(cnt < k && j + 1 < n) {
++j;
if(s[j] == 'J') ++cnt;
}
if(cnt >= k) jump[i][0] = j;
else jump[i][0] = n + n;
if(s[i] == 'J') --cnt;
} cnt = 0;
for(int i = 0, j = -1; i < n; ++i) {
while(cnt < k && j + 1 < n) {
++j;
if(s[j] == 'O') ++cnt;
}
if(cnt >= k) jump[i][1] = j;
else jump[i][1] = n + n;
if(s[i] == 'O') --cnt;
} cnt = 0;
for(int i = 0, j = -1; i < n; ++i) {
while(cnt < k && j + 1 < n) {
++j;
if(s[j] == 'I') ++cnt;
}
if(cnt >= k) jump[i][2] = j;
else jump[i][2] = n + n;
if(s[i] == 'I') --cnt;
}
int ans = n + n;
for(int i = 0, j; i < n; ++i) {
j = jump[i][0];
if(j >= n) continue;
j = jump[j][1];
if(j >= n) continue;
j = jump[j][2];
if(j >= n) continue;
ans = min(ans, j - i + 1 - k * 3);
}
if(ans == n + n) ans = -1;
cout << 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... |