Lights Off
시간 제한4초메모리 제한1024 MB
길이 N인 전구 문자열과 스위치 문자열이 주어지고, 한 번의 이동은 스위치 하나를 뒤집고 활성 스위치에 대응하는 전구를 토글한 뒤 스위치를 오른쪽으로 한 칸 회전시킬 때, 모든 전구를 끄는 최소 이동 횟수를 구한다.
문제
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.