Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×
Изменения рейтингов за последние раунды временно удалены. Скоро они будут возвращены. ×

Блог пользователя SXWisON

Автор SXWisON, история, 9 месяцев назад, По-английски

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;
}
Теги dp
  • Проголосовать: нравится
  • -13
  • Проголосовать: не нравится

»
9 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
9 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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