#P5910. Binary Matrix Construction for Optimization
Binary Matrix Construction for Optimization
Binary Matrix Construction for Optimization
Given an integer (D) and an (n \times m) real matrix (A = [a_{ij}]) where (0 \le a_{ij} \le D), your task is to construct an (n \times m) binary matrix (B = [b_{ij}]) with each element being either 0 or 1. For the provided matrices (A) and (B), two measures are computed as follows:
[
p_1 = \max \left{ \max_{1 \le j \le m} \left| \sum_{i=1}^n \left(b_{ij}-\frac{a_{ij}}{D}\right) \right|, \quad \max_{1 \le i \le n} \left| \sum_{j=1}^m \left(b_{ij}-\frac{a_{ij}}{D}\right) \right| \right}
]
[
p_2 = \max_{1 \le i \le n,, 1 \le j \le m} \left| b_{ij} + b_{i-1,j} + b_{i,j-1} + b_{i-1,j-1} - \frac{a_{ij}+a_{i-1,j}+a_{i,j-1}+a_{i-1,j-1}}{D} \right|
]
Your goal is to choose the matrix (B) so that either (p_1) or (p_2) is as small as possible. In this problem, you only need to output any valid binary matrix (B) that meets the constraints.
inputFormat
The first line contains three numbers: an integer (D), and two integers (n) and (m) representing the number of rows and columns of matrix (A), respectively.
Each of the next (n) lines contains (m) real numbers separated by spaces, representing the matrix (A). It is guaranteed that (0 \le a_{ij} \le D) for all valid (i) and (j).
outputFormat
Output (n) lines, each containing (m) integers (either 0 or 1) separated by a space, representing the binary matrix (B).
sample
5 2 3
0 2.5 5
1 3 4
0 0 0
0 0 0
</p>