This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* code by the cute ~~Dengdualang~~ PixelCat owo */
/* as cute as nacho neko (aka. my wife)! */
/* Nhade stay for a night here */
/* 183234 deng deng deng pixelcat oops */
/* (yang wang yesu)*2 */
/* ^ some weird stuff. nvm =w= */
#pragma GCC optimize("O4,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
// #define int LL //__int128
#define double long double
using namespace std;
using LL = long long;
using LLL = __int128_t;
using uLL = unsigned long long;
using pii = pair<int, int>;
#define For(i, a, b) for (int i = a; i <= b; i++)
#define Fors(i, a, b, s) for (int i = a; i <= b; i += s)
#define Forr(i, a, b) for (int i = a; i >= b; i--)
#define F first
#define S second
#define L(id) (id * 2 + 1)
#define R(id) (id * 2 + 2)
#define LO(x) (x & (-x))
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define mkp make_pair
#define MOD (int)(998244353)
// #define MOD (int)((LL)1e9 + 7)
// #define INF (int)(4e18) // 9e18
#define INF 1e9
#define EPS (1e-6)
#ifdef NYAOWO
#include "library/debug.hpp"
inline void USACO(const string &s) {
cerr << "USACO: " << s << "\n";
}
#else
#define debug(...)
inline void timer() {}
inline void USACO(const string &s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
#endif
inline void NYA() {
ios::sync_with_stdio(false);
cin.tie(0);
}
inline int gcd(int a, int b) {
return __gcd(a, b);
}
inline int lcm(int a, int b) {
return a / gcd(a, b) * b;
}
int fpow(int b, int p, const int &mod) {
int ans = 1;
while (p) {
if (p & 1) ans = ans * b % mod;
p >>= 1;
b = b * b % mod;
}
return ans;
}
int fpow(int b, int p) {
return fpow(b, p, MOD);
}
template <typename T>
inline void chmin(T &_a, const T &_b) {
if (_b < _a) _a = _b;
}
template <typename T>
inline void chmax(T &_a, const T &_b) {
if (_b > _a) _a = _b;
}
// mt19937_64 rng(
// chrono::steady_clock::now().time_since_epoch().count());
int a[200020];
int nxt[3][200020];
int32_t main() {
NYA();
// nyaacho >/////<
// miku sama bless me >/////<
int n,K; cin>>n>>K;
For(i,1,n){
char ch; cin>>ch;
if(ch=='J') a[i]=0;
else if(ch=='O') a[i]=1;
else a[i]=2;
}
For(ch,0,2){
queue<int> que;
For(i,1,n){
if(a[i]==ch) que.emplace(i);
if(sz(que)>K) que.pop();
if(sz(que)==K) nxt[ch][i]=que.front();
else nxt[ch][i]=-1;
// cout<<(nxt[ch][i]+(nxt[ch][i]==-1));
}
// cout<<"\n";
}
int ans=INF;
For(i,1,n){
int j=nxt[2][i]-1;
int k=(j<0?-1:nxt[1][j])-1;
int l=(k<0?-1:nxt[0][k]);
if(l>0){
// debug(i,l);
chmin(ans,i-l+1-K*3);
}
}
if(ans==INF) cout<<"-1\n";
else cout<<ans<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |