Problem D
Vin Diagrams
Venn diagrams were invented by the great logician John Venn
as a way of categorizing elements belonging to different sets.
Given two sets
![\includegraphics[width=0.3\textwidth ]{vin1}](/problems/vindiagrams/file/statement/en/img-0001.png)
One of John’s biggest fans was his grandson, Vin Vaughn
Venn. Vin was inspired by his grandfather’s diagrams, but Vin
was a very creative individual. Simple overlapping circles
struck Vin as too boring of a way to visualize the sometimes
messy intersections of categories, so he set out to make his
grandfather’s diagrams more interesting. Just like Venn
diagrams, Vin diagrams are used as a way of categorizing
elements belonging to different sets
In this problem, Vin diagrams will be laid out on a grid. Each set representation is a loop of ‘X’ characters, with one ‘X’ in each loop replaced by an ‘A’ or ‘B’ to identify the loop. All empty positions (both inside and outside of the loops) are represented by period (‘.’) characters, and the set of positions inside a loop is contiguous. Each loop character touches exactly two other loop characters either vertically or horizontally. Loops do not self-intersect, and other than the allowed horizontal/vertical paths and right angle connections, different parts of the loop do not touch (see Figures 2 and 3 below).
![\includegraphics[width=0.45\textwidth ]{vin2a}](/problems/vindiagrams/file/statement/en/img-0002.png)
![\includegraphics[width=0.45\textwidth ]{vin3a}](/problems/vindiagrams/file/statement/en/img-0003.png)
Loops A and B intersect at exactly two points. Loop intersection points always follow the pattern shown in Figure 4 (including the four ‘.’ positions around the intersection). No loop makes a right angle turn at an intersection point but always flows straight through the intersection, either vertically or horizontally. An example of legally intersecting loops is shown in Figure 5.
![\includegraphics[width=0.15\textwidth ]{vin4}](/problems/vindiagrams/file/statement/en/img-0004.png)
![\includegraphics[width=0.25\textwidth ]{vin5}](/problems/vindiagrams/file/statement/en/img-0005.png)
Input
The input starts with two integers
Output
Display, in order, the area of the Vin diagram exclusive to
set
Sample Input 1 | Sample Output 1 |
---|---|
7 7 AXXXX.. X...X.. X.XXXXX X.X.X.X XXXXX.X ..X...X ..XXXXB |
5 5 1 |
Sample Input 2 | Sample Output 2 |
---|---|
11 13 XXXXXXA...... X.....X...... X..XXXXXXXXX. X..X..X....X. X..X..XXX..XX X..B....X...X X..X.XXXX...X X..X.X......X XX.XXXXXX...X .X...X..X.XXX .XXXXX..XXX.. |
21 22 10 |