#include<bits/stdc++.h>
using namespace std;
int main() {
string s;
int K;
cin >> s >> K;
int n = s.length();
int rez = n;
int j, k, l, cj = 0, co = 0, ci = 0;
for (j = 0;j < n && cj < K;j++) {
if (s[j] == 'J')cj++;
}
if (cj != K) {
cout << -1;
return 0;
}
for (k = j;k < n && co < K;k++) {
if (s[k] == 'O')co++;
}
if (co != K) {
cout << -1;
return 0;
}
for (l = k;l < n && ci < K;l++) {
if (s[l] == 'I')ci++;
}
if (ci != K) {
cout << -1;
return 0;
}
for (int i = 0; i < n; i++) {
if (s[i] == 'J') {
cj--;
for (;j < n && cj < K;j++) {
if (s[j] == 'J')cj++;
if (s[j] == 'O')
for (;k < n && co < K;k++) {
if (s[k] == 'O')co++;
if (s[k] == 'I')
for (;l < n && ci < K;l++) {
if (s[l] == 'I')ci++;
}
}
}
}
if (cj == K && co == K && ci == K) {
rez = min(rez, l - i + 1 - 3 * K);
}
}
cout << rez;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |