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. ×

SXWisON's blog

By SXWisON, history, 9 months ago, In English

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
  • Vote: I like it
  • -13
  • Vote: I do not like it

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by SXWisON (previous revision, new revision, compare).

»
9 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by SXWisON (previous revision, new revision, compare).