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):
H, W = map(int, input().split())
a = []
for i in range(H):
    s = input()
    if s != '.'*W:
        a.append(s)
ls = []
for i in range(W):
    b = ''
    for j in range(len(a)):
        b += a[j][i]
    if b == '.'*len(a):
        ls.append(i)
ans = []
for i in range(W):
    s = ''
    for j in range(len(a)):
        if i in ls:
            continu
        else:
            s += a[j][i]
    ans.append(s)
print(*ans, sep='\n')

H, W = map(int, input().split())
a = []
for i in range(H):
    s = input()
    if s != '.'*W:
        a.append(s)
ls = []
for i in range(W):
    b = ''
    for j in range(len(a)):
        b += a[j][i]
    if b == '.'*len(a):
        ls.append(i)
ans = []
for i in range(W):
    s = ''
    for j in range(len(a)):
        if i in ls:
            continue
        else:
            s += a[j][i]
    ans.append(s)
print(*ans, sep='\n')

ｖH, W = map(int, input().split())
a = []
for i in range(H):
    s = input()
    if s != '.'*W:
        a.append(s)
ls = []
for i in range(W):
    b = ''
    for j in range(len(a)):
        b += a[j][i]
    if b == '.'*len(a):
        ls.append(i)
ans = []
for i in range(W):
    s = ''
    for j in range(len(a)):
        if i in ls:
            continue
        else:
            s += a[j][i]
    ans.append(s)
print(*ans, sep='\n')

H, W = map(int, input().split())
a = []
for i in range(H):
    s = input()
    if s != '.'*W:
        a.append(s)
ls = []
for i in range(W):
    cur = 0
    for j in range(len(a)):
        if a[j][i] == '.':
            cur += 1
    if cur == len(a):
        ls.append(i)
ans = a
for i in ls:
    for s in a:
        ans.append(s[:i] + s[i+1:])
print(*ans, sep='\n')

H, W = map(int, input().split())
a = []
for i in range(H):
    s = input()
    if s != '.'*W:
        a.append(input())
ls = []
for i in range(W):
    cur = 0
    for j in range(len(a)):
        if a[j][i] == '.':
            cur += 1
    if cur == len(a):
        ls.append(i)
ans = []
for i in ls:
    for s in a:
        ans.append(s[:i] + s[i+1:])
print(*ans, sep='\n')

H, W = map(int, input().split())
a = []
for i in range(H):
    s = input()
    if s != '.'*W:
        a.append(s)
ls = []
for i in range(W):
    b = ''
    for j in range(len(a)):
        b += a[j][i]
    if b == '.'*len(a):
        ls.append(i)
ans = []
for i in range(len(a)):
    s = ''
    for j in range(W):
        if j in ls:
            continue
        else:
            s += a[i][j]
    ans.append(s)
print(*ans, sep='\n')

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Time Limit Exceeded

Runtime Error

Accepted