#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1000000007
#define h1 7897897897897897
#define h2 7897466719774591
#define b1 98762051
#define b2 98765431
#define inf 1000000000
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pii>
#define SET(a, b) memset(a, b, sizeof(a));
#define all(x) (x).begin(), (x).end()
#define flush fflush(stdout)
#define debug printf("Hello\n")
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
//priority_queue <int, vector <int>, greater <int> > pq;
int n, m, k, x, y, sum, cnt, ans = -1;
string s;
bool check(int mid) {
int J = 0, O = 0, I = 0;
cnt = 0;
FOR(i, mid-1, n-1) {
if (J < k) {
if (s[i] == 'J') J++;
else cnt++;
} else if (O < k) {
if (s[i] == 'O') O++;
else cnt++;
} else if (I < k) {
if (s[i] == 'I') I++;
else cnt++;
}
if (J == k && O == k && I == k) {
ans = cnt;
return true;
}
}
return false;
}
int main () {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k >> s;
int lo = 0, hi = n-1, final = -1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (check(mid)) {
lo = mid + 1;
final = mid;
} else {
hi = mid - 1;
}
}
if (final == -1) cout << "-1" << endl;
else {
check(final);
cout << ans << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |