# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
216817 | oolimry | JJOOII 2 (JOI20_ho_t2) | C++14 | 11 ms | 4740 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> ii;
long long inf = 1e9;
long long pre[200005];
long long suf[200005];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
long long ans = inf;
int n, k; cin >> n >> k;
string s; cin >> s;
vector<int> O;
deque<long long> dq;
for(int i = 0;i < k;i++) dq.push_back(inf);
for(int i = 0;i < n;i++){
if(s[i] == 'J'){
dq.push_back(i);
dq.pop_front();
}
else if(s[i] == 'O'){
pre[i] = dq.front();
O.push_back(i);
}
}
dq.clear();
for(int i = 0;i < k;i++) dq.push_back(inf);
for(int i = n-1;i >= 0;i--){
if(s[i] == 'I'){
dq.push_back(i);
dq.pop_front();
}
else if(s[i] == 'O'){
suf[i] = dq.front();
}
}
for(int i = 0;i <= O.size() - k;i++){
long long L = pre[O[i]];
long long R = suf[O[i+k-1]];
if(L == inf || R == inf) continue;
ans = min(ans, R - L + 1);
}
if(ans >= inf/2) ans = -1;
else{
ans -= 3 * k;
}
cout << ans;
}
/*
10 2
OJIJOIOIIJ
*/
컴파일 시 표준 에러 (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... |