| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 532138 | scottchou | JJOOII 2 (JOI20_ho_t2) | C++17 | 9 ms | 1936 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
using namespace std;
vector<int> ipoint, opoint, jpoint;
int const N = 2e5 + 5;
int ov[N];
int inf = 1e9;
string s;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
cin >> s;
for(int i = 0; i < n; i++){
if(s[i] == 'I'){
ipoint.push_back(i);
}else if(s[i] == 'O'){
opoint.push_back(i);
}else{
jpoint.push_back(i);
}
}
int now = ipoint.size() - 1, minn = inf;
for(int i = opoint.size() - 1; i >= 0; i--){
if(i < k - 1){
ov[i] = inf;
continue;
}
int p = opoint[i];
while(now >= 0 && ipoint[now] > p){
if(now + k - 1 <= ipoint.size() - 1){
minn = ipoint[now + k - 1] + 1 - k;
}
now--;
}
if(minn == inf){
ov[i] = inf;
}else{
ov[i] = minn - opoint[i] - 1;
}
}
int ans = inf;
for(int i = 0; i < (int)jpoint.size() - k + 1; i++){
int op = lower_bound(opoint.begin(), opoint.end(), jpoint[i + k - 1]) - opoint.begin();
if(op + k - 1 >= opoint.size())
continue;
ans = min(ans, jpoint[i + k - 1] - jpoint[i] + 1 - k + opoint[op] - jpoint[i + k - 1] - 1 + ov[op + k - 1] + opoint[op + k - 1] - opoint[op] + 1 - k);
}
if(ans == inf){
cout << -1 << '\n';
}else{
cout << ans << '\n';
}
}
컴파일 시 표준 에러 (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... | ||||
