이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define MX(a,b) a=max(a,b)
#ifdef BALBIT
#define bug(...) cerr<<"#"<<#__VA_ARGS__<<": ", _do(__VA_ARGS__)
template<typename T> void _do(T && x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y){cerr<<x<<", "; _do(y...);}
#define IOS()
#else
#define IOS() ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define bug(...)
#endif // BALBIT
void GG(){cout<<-1<<endl; exit(0);}
const int maxn = 3e5+5;
int n,k; string s;
signed main(){
IOS();
bug(1,2);
cin>>n>>k;
cin>>s;
array<vector<int> ,3> kk;
for (int i = 0; i<n; ++i) {
if (s[i] == 'J') kk[0].pb(i);
if (s[i] == 'O') kk[1].pb(i);
if (s[i] == 'I') kk[2].pb(i);
}
int mnl = 10000000;
for (int i = 0; i<SZ(kk[0])-k+1; ++i) {
int to = kk[0][i+k-1];
int tmp = upper_bound(ALL(kk[1]), to) - kk[1].begin();
if (tmp + k-1 < SZ(kk[1])) {
to = kk[1][tmp+k-1];
}else continue;
tmp = upper_bound(ALL(kk[2]), to) - kk[2].begin();
if (tmp + k-1 < SZ(kk[2])) {
to = kk[2][tmp+k-1];
}else continue;
mnl = min(mnl, to - kk[0][i] + 1);
}
if (mnl > n) GG();
cout<<mnl - k*3<<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... |