a53

INF

a53
Oct 8th, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define Roc ios_base::sync_with_stdio(false), cin.tie(NULL)
  3. #define ll int
  4. #define NMAX 500009
  5. using namespace std;
  6. ll fr[4],n,k,act[4],ans,neww[4];
  7. char c;
  8. ifstream f("inf.in");
  9. ofstream g("inf.out");
  10. deque <char> Q;
  11. int code(char c)
  12. {
  13. if(c == 'I')
  14. return 1;
  15. if(c == 'N')
  16. return 2;
  17. if(c == 'F')
  18. return 3;
  19. }
  20. int main()
  21. {
  22. act[1] = 0;
  23. act[2] = 1;
  24. act[3] = 2;
  25. f >> n >> k;
  26. for(int i = 1; i <= k; ++i)
  27. {
  28. f >> c;
  29. Q.push_back(c);
  30. int cod = code(c);
  31. for(int j = 1; j <= 3; ++j)
  32. {
  33. act[j]++;
  34. if(act[j] > 3) act[j] -= 3;
  35. fr[j] += ( cod != act[j] );
  36. }
  37. }
  38. ans = fr[1];
  39. for(int i = 2; i <= 3; ++i)
  40. ans = min(ans, fr[i]);
  41. for(int i = k + 1; i <= n; ++i)
  42. {
  43. f >> c;
  44. Q.push_back(c);
  45. int cod = code(c);
  46. int cod2 = code(Q.front());
  47. Q.pop_front();
  48. for(int j = 1; j <= 3; ++j)
  49. {
  50. int prec = j - 1;
  51. if(prec == 0)
  52. prec = 3;
  53. neww[j] = fr[prec];
  54. neww[j] += ( cod != act[j] );
  55. neww[j] -= ( cod2 != prec );
  56. }
  57. for(int j = 1; j <= 3; ++j)
  58. {
  59. fr[j] = neww[j];
  60. ans = min(ans, fr[j]);
  61. }
  62.  
  63. }
  64. /*
  65. */
  66. g << ans;
  67. f.close();
  68. g.close();
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment