#PU1282. USACO 2023 January Contest, Gold — Problem 2. Lights Off
USACO 2023 January Contest, Gold — Problem 2. Lights Off
USACO 2023 January Contest, Gold — Problem 2. Lights Off
题目描述
Note: The time limit for this problem is 4s, twice the default. Bessie wants to go to sleep, but the farm's lights are keeping her awake. How can she turn them off? Bessie has two bit strings of length (), representing a sequence of lights and a sequence of switches, respectively. Each light is either on (1) or off (0). Each switch is either active (1) or inactive (0). A move consists of the following sequence of operations: Toggle exactly one switch (set it to active if it is inactive, or vice versa). For each active switch, toggle the state of the corresponding light (turn it off if it is on, or vice versa). Cyclically rotate the switches to the right by one. Specifically, if the bit string corresponding to the switches is initially then it becomes . For () instances of the problem above, count the minimum number of moves required to turn all the lights off.
输入格式
First line contains and . Next lines each contain a pair of length- bit strings.
输出格式
For each pair, the minimum number of moves required to turn all the lights off.
数据范围
Inputs 3-5: Inputs 6-13: Inputs 14-20: No additional constraints. Problem credits: William Yue, Eric Yang, and Benjamin Qi
样例
样例 1
4 3
000 101
101 100
110 000
111 000
0
1
3
2
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.
样例 2
1 10
1100010000 1000011000
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.