Problem: There is a grid of squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j). Each square is black or white. The color of the square is given as an H-by-W matrix (a_{i, j}). If a_{i, j} is `.`, the square (i, j) is white; if a_{i, j} is `#`, the square (i, j) is black.  Snuke is compressing this grid. He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:    * Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.  It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation. Find the final state of the grid.

Submission attempts (in order):
import numpy as np


def yoko(row):
    cnt = sum(row)
    return cnt == len(row)


def main():
    h, w = map(int, input().split(' '))
    a = []

    for i in range(h):
        b = input()
        a += [1 if c == '.' else 0 for c in b]
    a = np.array(a).reshape(h, w)

    while True:
        cnt = 0
        del_list = []
        for i in range(len(a)):
            judge = yoko(a[i])
            if judge:
                del_list.append(i)

        if len(del_list):
            del_cnt = 0
            for idx in del_list:
                a = np.delete(a, idx - del_cnt, axis=0)
                del_cnt += 1
        else:
            cnt += 1

        a = a.T

        print('-------')
        print(a)

        del_list = []
        for i in range(len(a)):
            judge = yoko(a[i])
            if judge:
                del_list.append(i)

        if len(del_list):
            del_cnt = 0
            for idx in del_list:
                a = np.delete(a, idx - del_cnt, axis=0)
                del_cnt += 1
        else:
            cnt += 1

        a = a.T

        if cnt >= 2:
            break

    for i in range(len(a)):
        r = ''
        for j in a[i]:
            if j == 1:
                r += '.'
            else:
                r += '#'
        print(r)


main()


import numpy as np


def yoko(row):
    cnt = sum(row)
    return cnt == len(row)


def main():
    h, w = map(int, input().split(' '))
    a = []

    for i in range(h):
        b = input()
        a += [1 if c == '.' else 0 for c in b]
    a = np.array(a).reshape(h, w)

    while True:
        cnt = 0
        del_list = []
        for i in range(len(a)):
            judge = yoko(a[i])
            if judge:
                del_list.append(i)

        if len(del_list):
            del_cnt = 0
            for idx in del_list:
                a = np.delete(a, idx - del_cnt, axis=0)
                del_cnt += 1
        else:
            cnt += 1

        a = a.T

        del_list = []
        for i in range(len(a)):
            judge = yoko(a[i])
            if judge:
                del_list.append(i)

        if len(del_list):
            del_cnt = 0
            for idx in del_list:
                a = np.delete(a, idx - del_cnt, axis=0)
                del_cnt += 1
        else:
            cnt += 1

        a = a.T

        if cnt >= 2:
            break

    for i in range(len(a)):
        r = ''
        for j in a[i]:
            if j == 1:
                r += '.'
            else:
                r += '#'
        print(r)


main()


Verdicts: Wrong Answer

Accepted