Please read the new rule regarding the restriction on the use of AI tools. ×
Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

Problem Notes

Revision en3, by SXWisON, 2023-12-21 05:09:42

698A - Каникулы

SXWisON molingspance

Idea

A variable p can be used to represent the available actions, with the following rules:

  • If no action can be performed on that day, let p=0.
  • If the input is x=1,2 and can be executed, then the possible action for p is x, that is p=x.
  • If the input is x=3, there are two possibilities. Either both states can be performed, or only one of them can be executed.

If the previous value of p is 0, than the current value is 3, that means all actions can be executed.

If the previous value of p is 1, the current value must be 2.

Similarly, if the previous value of p is 2, the current value must be 1.

It’s interesting that all the calculations can be expressed as p=3-p.

It's easy to determine that a specific day cannot excute any actions is equivalent to:

Either x=0 (indicating that no venues are open) or x=p and x is not 3. If x is not 3, it means that the only action that can be taken is exactly the same as the only action that could be taken the previous day, violating the rest principle. Therefore, on that day, no actions can be performed.

Code

#include <iostream>
 
int main(int argc, char* argv[]) {
  int n, x, p = 3, ans = 0;
  std::cin >> n;
  for (int i = 1; i <= n; i++) {
    std::cin >> x;
    if (x == 0 || (x == p && x != 3))
      ans++, p = 0;
    else
      p = (x == 3) ? 3 - p : x;
  }
  std::cout << ans;
  return 0;
}
Tags dp

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English SXWisON 2023-12-21 05:09:42 664
en2 English SXWisON 2023-12-20 19:11:26 0 (published)
en1 English SXWisON 2023-12-20 19:08:11 1508 Initial revision (saved to drafts)