QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#4172. Optimal Image

Statistics

Little E discovered a magical picture at his friend Little W's house and became quite interested in it. It can be viewed as a black-and-white image containing $N \times M$ pixels. For convenience, we use 0 to represent a white pixel and 1 to represent a black pixel. Little E believes this picture hides a mystery, so he recorded the number of black pixels in each row and each column to study its secrets later.

One day, Little W accidentally got the picture wet, and the original image became difficult to distinguish. He was very anxious, so he asked Little E to help restore the picture together. Based on the damaged picture, they cannot determine the true image, but they can infer the probability $P_{ij}\%$ that each pixel was originally a black pixel. Thus, the probability of a complete image appearing can be defined as:

$$\prod_{1 \le i \le N, 1 \le j \le M, S_{ij}=1} \frac{P_{ij}}{100}$$

where $S_{ij}$ represents whether the pixel is white (0) or black (1) in the restored image. In other words, the probability of a complete image appearing is equal to the product of the probabilities of all its black pixels. Obviously, the black pixels of the image cannot include pixels with a probability of 0.

However, Little E was helpless in this situation. Therefore, they found Little F, who knows how to program—that is, you. Please use the information above to tell them what the most likely original image is.

Input

The first line contains two positive integers $N$ and $M$, representing the size of the image.

The next $N$ lines each contain $M$ integers, representing the probability $P_{ij}\%$ that each pixel is a black pixel, where $0 \le P_{ij} < 100$.

The next line contains $N$ non-negative integers, representing the number of black pixels in each row.

The next line contains $M$ non-negative integers, representing the number of black pixels in each column.

Output

The output contains an $N \times M$ matrix of 0s and 1s, representing the restored image. Do not include spaces in the output.

The number of 1s in each row and column of the image must match the input, and it must be the one with the highest probability among all possible images. The input data guarantees that at least one possible image exists. If there are multiple optimal images, you may output any one of them.

Examples

Input 1

2 2
90 10
20 80
1 1
1 1

Output 1

10
01

Note 1

There are two possible images:

01
10

and

10
01

The probability of the former is $0.1 \times 0.2 = 0.02$, and the probability of the latter is $0.9 \times 0.8 = 0.72$, so the latter is the optimal image.

Constraints

For 20% of the data, $N, M \le 5$.

For 100% of the data, $N, M \le 100$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.