fork download
  1. // Quiz 2 Nomor A - Bezaleel Steven Jadimadapot Sihotang
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main() {
  6. unsigned int n;
  7. cin >> n;
  8.  
  9. unsigned int a[n];
  10. for (int i = 0; i < n; i++) {
  11. cin >> a[i];
  12. }
  13.  
  14. bool gym_is_opened; bool IT_contest_is_carried_out;
  15. unsigned int rest = 0;
  16. if (a[0] == 0) {
  17. gym_is_opened = false;
  18. IT_contest_is_carried_out = false;
  19. rest++;
  20. }
  21. if (a[0] == 1) {
  22. gym_is_opened = false;
  23. IT_contest_is_carried_out = true;
  24. }
  25. if (a[0] == 2) {
  26. gym_is_opened = true;
  27. IT_contest_is_carried_out = false;
  28. }
  29. if (a[0] == 3) {
  30. gym_is_opened = true;
  31. IT_contest_is_carried_out = true;
  32. }
  33.  
  34. if (a[1] == 1) {
  35. gym_is_opened = false;
  36. IT_contest_is_carried_out = true;
  37. if (a[1] == a[0]) {
  38. if (IT_contest_is_carried_out) {
  39. IT_contest_is_carried_out = false;
  40. }
  41. }
  42. }
  43. if (a[1] == 2) {
  44. gym_is_opened = true;
  45. IT_contest_is_carried_out = false;
  46. if (a[1] == a[0]) {
  47. if (gym_is_opened) {
  48. gym_is_opened = false;
  49. }
  50. }
  51. }
  52. if (a[1] == 3) {
  53. gym_is_opened = true;
  54. IT_contest_is_carried_out = true;
  55. if (a[1] == a[0]) {
  56. if (gym_is_opened) {
  57. gym_is_opened = false;
  58. }
  59. if (IT_contest_is_carried_out) {
  60. IT_contest_is_carried_out = false;
  61. }
  62. }
  63. }
  64. if (not IT_contest_is_carried_out && not gym_is_opened) {
  65. rest++;
  66. }
  67. if (a[1] == 0) {
  68. gym_is_opened = false;
  69. IT_contest_is_carried_out = false;
  70. rest++;
  71. }
  72.  
  73. for (int i = 2; i < n; i++) {
  74. if (a[i] == 0) {
  75. gym_is_opened = false;
  76. IT_contest_is_carried_out = false;
  77. rest++;
  78. continue;
  79. }
  80. if (a[i] == 1) {
  81. gym_is_opened = false;
  82. IT_contest_is_carried_out = true;
  83. if (a[i] == a[i - 1] || a[i] == a[i - 2]) {
  84. if (gym_is_opened) {
  85. gym_is_opened = false;
  86. }
  87. if (IT_contest_is_carried_out) {
  88. IT_contest_is_carried_out = false;
  89. }
  90. }
  91. }
  92. if (a[i] == 2) {
  93. gym_is_opened = true;
  94. IT_contest_is_carried_out = false;
  95. if (a[i] == a[i - 1] || a[i] == a[i - 2]) {
  96. if (gym_is_opened) {
  97. gym_is_opened = false;
  98. }
  99. if (IT_contest_is_carried_out) {
  100. IT_contest_is_carried_out = false;
  101. }
  102. }
  103. }
  104. if (a[i] == 3) {
  105. gym_is_opened = true;
  106. IT_contest_is_carried_out = true;
  107. if (a[i] == a[i - 1] || a[i] == a[i - 2]) {
  108. if (gym_is_opened) {
  109. gym_is_opened = false;
  110. }
  111. if (IT_contest_is_carried_out) {
  112. IT_contest_is_carried_out = false;
  113. }
  114. }
  115. }
  116. if (not IT_contest_is_carried_out && not gym_is_opened) {
  117. rest++;
  118. }
  119. }
  120.  
  121. cout << rest;
  122. }
Success #stdin #stdout 0s 5316KB
stdin
4
1 3 2 0
stdout
1