제출 #1156396

#제출 시각아이디문제언어결과실행 시간메모리
1156396zhasynJJOOII 2 (JOI20_ho_t2)C++20
100 / 100
5 ms1236 KiB
//#include "gondola.h" #include <bits/stdc++.h> #define pb push_back #define pf push_front using namespace std; #define F first #define S second typedef long long ll; #define pii pair <int, int> #define pll pair <ll, ll> typedef long double ld; const ll N = 2 * 1e5 + 100, M = 1e7 + 10, len = 21, inf = 1e18; const ll mod = 1000000009LL; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll um(ll a, ll b){ return (1LL * a * b) % mod; } ll subr(ll a, ll b){ return ((1LL * a - b) % mod + mod) % mod; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, k, ans = INT_MAX; cin >> n >> k; string s; cin >> s; deque <int> v1, v2, v3; for(int i = 0; i < n; i++){ if(s[i] == 'J') v1.pb(i); if(s[i] == 'O') v2.pb(i); if(s[i] == 'I') v3.pb(i); } while((int)v1.size() >= k){ while((int)v2.size() > 0){ if(v2[0] < v1[k - 1]) v2.pop_front(); else break; } if((int)v2.size() < k) break; while((int)v3.size() > 0){ if(v3[0] < v2[k - 1]) v3.pop_front(); else break; } if((int)v3.size() < k) break; ans = min(ans, v3[k - 1] - v1[0] + 1 - 3 * k); v1.pop_front(); } if(ans == INT_MAX) cout << -1; else cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...