#P1524. 十字绣
十字绣
Description
The cloth is an grid. The thread can pass from one side of the cloth to the other only at the grid vertices. Each segment of thread covers one of the two diagonals of a unit cell, and during stitching, two consecutive segments within a single stitch must lie on opposite sides of the cloth. Given the patterns on both sides of the cloth (solid lines indicate a thread on this side, dashed lines indicate a thread on the opposite side), determine the minimum number of stitches needed to complete the embroidery. A stitch is a single embroidery process during which the needle does not leave the fabric.

Input Format
The first line contains two numbers and ().
The next lines each contain characters describing the front side.
The following lines each contain characters describing the back side.
Each cell is represented as follows:
- means empty.
- means a thread from the top-right corner to the bottom-left corner.
- means a thread from the top-left corner to the bottom-right corner.
- means the two diagonals cross.
Output Format
Output a single integer, the minimum number of stitches required.
4 5
.....
.\...
..\..
.....
.....
....\
.\X..
.....
4
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号