이 제출은 이전 버전의 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 = min(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) 메시지
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:32:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | if(now + k - 1 <= ipoint.size() - 1){
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:46:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | if(op + k - 1 >= opoint.size())
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |