Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define Roc ios_base::sync_with_stdio(false), cin.tie(NULL)
- #define ll int
- #define NMAX 500009
- using namespace std;
- ll fr[4],n,k,act[4],ans,neww[4];
- char c;
- ifstream f("inf.in");
- ofstream g("inf.out");
- deque <char> Q;
- int code(char c)
- {
- if(c == 'I')
- return 1;
- if(c == 'N')
- return 2;
- if(c == 'F')
- return 3;
- }
- int main()
- {
- act[1] = 0;
- act[2] = 1;
- act[3] = 2;
- f >> n >> k;
- for(int i = 1; i <= k; ++i)
- {
- f >> c;
- Q.push_back(c);
- int cod = code(c);
- for(int j = 1; j <= 3; ++j)
- {
- act[j]++;
- if(act[j] > 3) act[j] -= 3;
- fr[j] += ( cod != act[j] );
- }
- }
- ans = fr[1];
- for(int i = 2; i <= 3; ++i)
- ans = min(ans, fr[i]);
- for(int i = k + 1; i <= n; ++i)
- {
- f >> c;
- Q.push_back(c);
- int cod = code(c);
- int cod2 = code(Q.front());
- Q.pop_front();
- for(int j = 1; j <= 3; ++j)
- {
- int prec = j - 1;
- if(prec == 0)
- prec = 3;
- neww[j] = fr[prec];
- neww[j] += ( cod != act[j] );
- neww[j] -= ( cod2 != prec );
- }
- for(int j = 1; j <= 3; ++j)
- {
- fr[j] = neww[j];
- ans = min(ans, fr[j]);
- }
- }
- /*
- */
- g << ans;
- f.close();
- g.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment