#P1740. Diamond A&B(1)

Diamond A&B(1)

Description

The Guru is on TV! This news is absolutely explosive. As soon as it spreads, the streets instantly become empty (everyone went home to watch TV), shops close, and factories stop. Everyone turns their TV volume to the maximum, and the Guru’s voice echoes through the streets and alleys.

Xiao L hurriedly turns on the TV at home and finds that all channels are broadcasting the Guru’s interview program (-_-bbb). On the screen, the smiling Guru presents a difficult task:

A large diamond with side length nn is evenly divided into an n×nn \times n grid made of unit diamonds with side length 11. However, some edges in the grid have been erased. Xiao L wants to know how many parallelograms are inside the large diamond whose interiors contain no edges (i.e., the interior is empty).

This task is split into two subproblems. In this subproblem (Diamond A), given the diamond-shaped grid described by slashes and backslashes below, please convert it into an axis-aligned rectangular grid and output the presence of edges as 0/10/1 in the specified format. The actual counting of parallelograms is handled in Diamond B.

Input Format

  • The first line contains a positive integer nn, the side length of the large diamond.

  • The next 2n2n lines each contain 2n2n characters. Each character is one of: a space, /\verb!/!, or \\verb!\!.

  • For the first nn lines (the upper half of the diamond), the ii-th line (1-indexed) has exactly 2i2i non-space positions centered in the line. Among these 2i2i positions:

    • Characters at odd positions can only be /\verb!/! or a space.
    • Characters at even positions can only be \\verb!\! or a space. A space means that the corresponding edge does not exist. All other characters outside these centered 2i2i positions are spaces. These lines describe the upper half of the diamond.
  • For the last nn lines (the lower half of the diamond), the ii-th line (1-indexed within the lower half) has exactly 2(ni+1)2(n - i + 1) non-space positions centered in the line, described in the same way as above, forming the lower half of the diamond.

  • It is guaranteed that no edge on the outer boundary of the large diamond is erased.

Output Format

  • The first line outputs the integer nn.

  • Then output 2n+12n+1 lines that describe the edges after converting the diamond grid into an n×nn \times n axis-aligned rectangular grid (think of rotating by 4545^\circ and scaling). Use 11 for an existing edge and 00 for a missing edge. Specifically:

    • Lines 11 to n+1n+1: horizontal edges. Each of these lines contains exactly nn characters, each being 00 or 11. The jj-th character on line ii (1-indexed) indicates whether the horizontal edge between grid points (i1,j1)(i-1, j-1) and (i1,j)(i-1, j) exists.
    • Lines n+2n+2 to 2n+12n+1: vertical edges. Each of these lines contains exactly n+1n+1 characters, each being 00 or 11. Let r=i(n+1)r = i - (n+1) for line index ii in this range. The jj-th character on line ii indicates whether the vertical edge between grid points (r1,j1)(r-1, j-1) and (r,j1)(r, j-1) exists.
4
   /\   
  /\/\  
 /\  /\ 
/  \/  \
\/\/ / /
 \/\  / 
  \ \/  
   \/   

4
1111
11101
1000
10111
1100
10101
0111
11101
1111

Hint

Constraints

  • For 20%20\% of the testdata, n10n \le 10.
  • For 40%40\% of the testdata, n60n \le 60.
  • For 60%60\% of the testdata, n200n \le 200.
  • For 100%100\% of the testdata, n888n \le 888.

Translated by ChatGPT 5