#P7034. [NWRRC2016] Digital Addition

[NWRRC2016] Digital Addition

题目描述

Deidra is doing a columnar addition. She writes down two non-negative integer summands one below the other, left-pads them with zeroes so that they have equal length, and calculates the sum (e.g.  77+05=82 77 + 05 = 82) . If the sum is longer than each of the summands (because of a carry, as in 96+07=10396 + 07 = 103) she appends a zero at the beginning of each summand (096+007=103)096 + 007 = 103) . She allows herself to use unnecessary leading zeroes ( 007+004=011)007 + 004 = 011) as soon as the length of all three numbers is the same.

Also Deidra has a homemade printing press. She decided to print her addition without a plus or a horizontala horizontal line, using the following standard font:

Unfortunately, she messed up with spacing, and all the digits were printed over each other in the following way. Digits that were supposed to be horizontally adjacent were printed so that the right two segments of the left digit coincide with the left two segments of the right digit. Digits that were supposed to be vertically adjacent were printed so that the bottom half (a square with 4 segments) of the upper digit coincides with the top half of the lower digit.

When one or more black segments are printed at the same position, the result looks black. When only empty segments are printed at the position, the result looks white.

Given the resulting picture, find a correct addition that could produce it or detect that there is none.

输入格式

The first line of the input contains an integer w(1w100)w (1 \le w \le 100) -- the width of Deidra's addition (number of(number of digits in each line).

The following 99 lines contain the description of the picture printed with the bad spacing. Each line contains ww or w+1w + 1 digits. ‘1' denotes a black segment, ‘0' denotes a white one. Even lines start with a space. See the examples for clarification.

输出格式

If there is no valid addition, output NO.

Otherwise output a valid addition that produces the given figure. The output should consist of three lines, each containing ww digits.

If there are several solutions, output any of them.

题目大意

Deidra正在做一个列式的加法。她写下两个正整数来对其进行求和,且一个在另一个下方,在它们的左边添0,使得他们拥有相同的长度,然后相加计算结果(例如 77+05=8277 + 05 = 82)。如果这个结果的长度大于这两个加数任何一个的长度(由于进位,例如96+07=10396 + 07 = 103),就在两个加数前面附加零(096+007=103096 + 007 = 103)。她允许不必要的前导零的出现(007+004=011007 + 004 = 011)只要算式中的三个数字的长度都相同。

Deidra还有一台自制的打印机。她决定在没有加号和水平线的情况下打印她的加法算式,使用下面的标准字体

不幸的是,她弄乱了这些数字的间距,所有的数字都将以以下方式打印。打印这些本应水平相邻的数字时左边数字的右两段与右边数字的左两端重合。打印应该竖直相邻的数字时,上边数字的下半部分(由四段组成的正方形部分)与下边数字的上半部分重合。

如果在同一位置打印一个或多个线段时,将显示为黑色。当所在位置仅打印空段时,将显示为白色。

给定一个生成的图片,找到可以通过打印机产生这个图片的正确算式。如果找不到符合要求的算式,就输出 NO

输入格式

第一行包含一个整数ww(1w100)(1\le w \le 100) 代表Deidra加法的宽度(接下来每行的数字个数)

接下来的99行包含对于用错误打印机输出的图片的描述。每行包含www+1w+1个数字。"1"表示黑色段,"0"表示白色段。偶数行以空格开头。有关说明请参阅样例。

输出格式

如果没有符合要求的算式,则输出 NO

否则输出给定图片所对应的有效算式。输出应由三行组成,每行包含ww个数字。

如果有多个符合规定的算式,请输出其任何一个。

2
 1 1
0 1 1
 1 0
0 1 1
 1 1
0 1 1
 1 0
0 1 1
 0 0

37
34
71

1
 1
0 1
 1
1 1
 1
1 1
 1
0 1
 0

2
2
4

1
 1
1 0
 1
1 1
 1
1 1
 1
0 1
 0

NO

提示

Time limit: 2 s, Memory limit: 256 MB.