Nima Moradi Interview1

mail@pastecode.io avatar
unknown
python
2 years ago
1.2 kB
4
Indexable
Never
# Input
# 2 3
# 0 1 0
# 1 1 1

# Output
# YES
# 0 0 0
# 0 1 0


def print_matrix(matrix):
    for row in matrix:
        for item in row:
            print(f'{item} ', end="")
        print()


def main():
    rows, cols = map(int, input().split(" "))
    matrix = []
    matrix_sum = 0
    calculated_rows, calculated_cols = [], []
    for _ in range(rows):
        row = [int(x) for x in input().split(" ")]
        matrix.append(row)
        row_sum = sum(row)
        matrix_sum += row_sum
        calculated_rows.append(row_sum // cols)

    for j in range(cols):
        col_sum = 0
        for i in range(rows):
            col_sum += matrix[i][j]
        calculated_cols.append(col_sum // rows)

    if matrix_sum == 0:
        print("YES")
        print_matrix(matrix)
        return
    result_matrix = []
    for i in range(rows):
        row = []
        for j in range(cols):
            row.append(calculated_rows[i] & calculated_cols[j])
        result_matrix.append(row)
    for row in result_matrix:
        for item in row:
            if item == 1:
                print("YES")
                print_matrix(result_matrix)
                return
    print("NO")


if __name__ == '__main__':
    main()