이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int mx = 2e5+5;
const int inf = 1e9+1;
int n, k;
string st;
int main() {
cin.tie(0);ios::sync_with_stdio(0);
cin >> n >> k;
cin >> st;
int z, x, c, v, cj, co, ci;
z = x = c = v = 0;
cj = co = ci = 0;
int ans = inf;
while (z<n&&st[z]!='J') z++;
x = z;
while (x!=n&&cj<k) {
if (st[x] == 'J') cj++;
x++;
}
c = x;
// cout << cj << " " << co << " " << ci << "\n";
while (c!=n&&co<k) {
if (st[c] == 'O') co++;
c++;
}
v = c;
while (v!=n&&ci<k) {
if (st[v] == 'I') ci++;
v++;
}
// cout << z << " " << x << " " << c << " " << v << " " << cj << " " << co << " " << ci << "owo\n";
if (cj == k and co == k and ci == k) {
ans = v-z-3*k;
} else {
cout << -1 << "\n";
return 0;
}
for (;x<n;) {
while (z<n&&st[z]!='J') z++;
cj--;
while (x!=n&&cj<k) {
if (st[x] == 'J') cj++;
if (st[x] == 'O') co--;
x++;
}
while (c!=n&&co<k) {
if (st[c] == 'O') co++;
if (st[c] == 'I') ci--;
c++;
}
while (v!=n&&ci<k) {
if (st[v] == 'I') ci++;
v++;
}
if (cj == k and co == k and ci == k) {
ans = min(ans,v-x+1-3*k);
}
}
cout << ans << "\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... |