제출 #628603

#제출 시각아이디문제언어결과실행 시간메모리
628603colossal_pepeJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
25 ms2956 KiB
#include <iostream> #include <algorithm> using namespace std; int n, k; string s; int solve() { int a[n], b[n], c[n]; for (int i = 0; i < n; i++) { a[i] = b[i] = c[i] = 0; a[i] += (s[i] == 'J'); b[i] += (s[i] == 'O'); c[i] += (s[i] == 'I'); if (i) { a[i] += a[i - 1]; b[i] += b[i - 1]; c[i] += c[i - 1]; } } int ans = n; for (int i = 0; i < n; i++) { int j = lower_bound(a, a + n, k + (i ? a[i - 1] : 0)) - a; if (j == n) break; j = lower_bound(b, b + n, k + b[j]) - b; if (j == n) break; j = lower_bound(c, c + n, k + c[j]) - c; if (j == n) break; ans = min(ans, j - i + 1 - 3 * k); } return (ans != n ? ans : -1); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k >> s; cout << solve() << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...