제출 #475908

#제출 시각아이디문제언어결과실행 시간메모리
475908ymmJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
11 ms2504 KiB
/// /// 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...