이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn = 4e5 + 10;
int n, k;
int J[maxn], O[maxn], I[maxn];
int nex(int t, int par[]){
int lo = t - 1, hi = n;
while (hi - lo > 1){
int mid = (lo + hi) >> 1;
if (par[mid + 1] - par[t] >= k)
hi = mid;
else
lo = mid;
}
return hi;
}
int main(){
ios_base::sync_with_stdio(false);
string s;
cin >> n >> k;
cin >> s;
for (int i = 0; i < n; i++){
J[i + 1] = J[i] + (s[i] == 'J');
O[i + 1] = O[i] + (s[i] == 'O');
I[i + 1] = I[i] + (s[i] == 'I');
}
int answer = -1;
for (int i = 0; i < n; i++){
int t = nex(i, J);
t = nex(t, O);
t = nex(t, I);
if (t >= n)
break;
if (answer == -1 or answer > (t - i + 1 - 3 * k))
answer = t - i + 1 - 3 * k;
}
cout << answer << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |