이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<int> J, O, I;
char a[200005];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k, Osz, Isz, ans=1e9;
cin >> n >> k;
for (int i=1; i<=n; i++)
{
cin >> a[i];
if (a[i]=='J')
J.push_back(i);
else if (a[i]=='O')
O.push_back(i);
else
I.push_back(i);
}
Osz=O.size();
Isz=I.size();
for (int i=0; i<=Osz-k; i++)
{
int index=lower_bound(J.begin(), J.end(), O[i])-J.begin()-k;
int jndex=lower_bound(I.begin(), I.end(), O[i+k-1])-I.begin()+k-1;
if (index>=0 && jndex<Isz)
ans=min(ans, I[jndex]-J[index]+1-k*3);
}
if (ans==1e9)
cout << -1;
else
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |