P9017 [USACO23JAN] Lights Off G
题目描述
给定正整数 $N$,和两个长为 $N$ 的 $01$ 序列 $a$ 和 $b$。定义一次操作为:
1. 将 $b$ 序列中的一个值翻转(即 $0$ 变成 $1$,$1$ 变成 $0$,下同)。
2. 对于 $b$ 序列中每个值为 $1$ 的位置,将 $a$ 序列中对应位置的值翻转。
3. 将 $b$ 序列向右循环移位 $1$ 位。即若当前 $b$ 序列为 $b_1b_2\cdots b_{n}$,则接下来变为 $b_{n}b_1b_2\cdots b_{n-1}$。
有 $T$ 次询问,对每一次询问,你需要回答出至少需要几次操作,才能使 $a$ 序列中每一个位置的值都变为 $0$。
输入格式
无
输出格式
无
说明/提示
### Explanation for Sample 1
- First test case: the lights are already all off.
- Second test case: We flip the third switch on the first move.
- Third test case: we flip the first switch on the first move, the second switch on the second move, and the second switch again on the third move.
- Fourth test case: we flip the first switch on the first move and the third switch on the second move.
It can be shown that in each case this is the minimal number of moves necessary.
### Explanation for Sample 2
It can be shown that $2$ moves are required to turn all lights off.
- We flip the seventh switch on the first move and then again on the second move.
### Scoring
- Inputs $3-5$: $N \le 8$
- Inputs $6-13$: $N \le 18$
- Inputs $14-20$: No additional constraints.