이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
///
/// Let the voice of love take you higher!
///
#define _USE_MATH_DEFINES
#define FAST ios::sync_with_stdio(false),cin.tie(0);
#include <bits/stdc++.h>
#define Loop(x, l, r) for(ll x = ll(l); x < ll(r); ++x)
#define LoopR(x, l, r) for(ll x = ll(r)-1; x >= ll(l); --x)
#define all(x) x.begin(), x.end()
#define Kill(x) exit((cout << (x) << '\n', 0))
#define YN(flag) ((flag)? "YES": "NO")
#define F first
#define S second
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> pii;
typedef std::pair<ll ,ll > pll;
using namespace std;
const int N = 200010;
vector<pii> J, I;
int n, k;
int main()
{
FAST;
cin >> n >> k;
int cnt = 0;
Loop(i,0,n)
{
char c;
cin >> c;
if(toupper(c) == 'J') J.push_back({i,cnt});
if(toupper(c) == 'I') I.push_back({i,cnt});
if(toupper(c) == 'O') ++cnt;
}
int ans = INT_MAX;
int p1 = k-1;
int p2 = 0;
while(p1 < (ll)J.size())
{
while(p2 <= (ll)I.size()-k && I[p2].S - J[p1].S < k) ++p2;
if(p2 > (ll)I.size()-k) break;
ans = min(ans, I[p2+k-1].F-J[p1-k+1].F+1-3*k);
++p1;
}
cout << (ans==INT_MAX?-1:ans) << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |