Advertisement
Mirbek

A. SWAP

Jan 26th, 2022
684
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     string s;
  7.     cin >> s;
  8.  
  9.     int n = s.size();
  10.     s = ' ' + s;
  11.  
  12.     int k = 0;
  13.  
  14.     vector <int> pf(n + 1);
  15.     for (int i = 1; i <= n; i++) {
  16.         pf[i] = pf[i - 1];
  17.         if (s[i] == 'K') {
  18.             k++;
  19.         } else {
  20.             pf[i]++;
  21.         }
  22.     }
  23.  
  24.     int ans = n;
  25.     for (int i = k; i <= n; i++) {
  26.         ans = min(ans, pf[i] - pf[i - k]);
  27.     }
  28.  
  29.     cout << ans << endl;
  30. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement