This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;
ll INF=LLONG_MAX;
int const mxn=2e5+5;
vi dp[3];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int n,k; string s;
cin >> n >> k >> s;
for(int i=0; i<n; i++){
if(s[i]=='J')dp[0].pb(i);
else if(s[i]=='O')dp[1].pb(i);
else dp[2].pb(i);
}
int ans=1e9;
for(int i=0; i<(int)dp[0].size()-k+1; i++){
int posini = dp[0][i];
int posj = dp[0][i+k-1];
int poso = upper_bound(all(dp[1]),posj)-dp[1].begin();
if(poso==(int)dp[1].size())break;
poso += k-1;
if(poso>=(int)dp[1].size())break;
poso = dp[1][poso];
int posi = upper_bound(all(dp[2]),poso)-dp[2].begin();
if(posi==(int)dp[2].size())break;
posi += k-1;
if(posi>=(int)dp[2].size())break;
posi = dp[2][posi];
ans = min(ans, posi-posini+1-k*3);
}
if(ans==1e9)ans=-1;
cout << ans << 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... |