이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " " << (x) << endl;
#define V vector
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int k, n;
string s;
cin >> n >> k >> s;
int mx = -1;
vi js, os, is;
for(int i = 0; i < n; i++) {
if(s[i] == 'J') js.PB(i);
else if(s[i] == 'O') os.PB(i);
else is.PB(i);
}
for(int i = 0; i + k - 1 < (int)js.size(); i++) {
int j = js[i + k - 1];
j = lower_bound(ALL(os), j) - os.begin();
if(j + k - 1 >= (int)os.size()) break;
j = os[j + k - 1];
j = lower_bound(ALL(is), j) - is.begin();
if(j + k - 1 >= (int)is.size()) break;
j = is[j + k - 1];
mx = max(mx, js[i] + n - 1 - j);
}
if(mx == -1) cout << -1 << endl;
else {
cout << n-mx-3*k << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |