Problem:


Score : 200 points

Problem Statement

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.

Constraints

1 \leq H, W \leq 100

a_{i, j} is . or #.

There is at least one black square in the whole grid.

Input

Input is given from Standard Input in the following format:

H W
a_{1, 1}...a_{1, W}
:
a_{H, 1}...a_{H, W}

Output

Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity.

Sample Input 1

4 4
##.#
....
##.#
.#.#

Sample Output 1

###
###
.##

The second row and the third column in the original grid will be removed.

Sample Input 2

3 3
#..
.#.
..#

Sample Output 2

#..
.#.
..#

As there is no row or column that consists only of white squares, no operation will be performed.

Sample Input 3

4 5
.....
.....
..#..
.....

Sample Output 3

#

Sample Input 4

7 6
......
....#.
.#....
..#...
..#...
......
.#..#.

Sample Output 4

..#
#..
.#.
.#.
#.#



Sample input:
4 4
##.#
....
##.#
.#.#


Sample output:
###
###
.##

Submission status: Wrong Answer

Solution code:
# coding:utf-8
import numpy as np

H, W = map(int, input().split())
cell = []
for i in range(H):
    cell.append(input())

mat = np.empty((H, W))
for i in range(H):
    for j in range(W):
        if cell[i][j] == '.':
            mat[i,j] = 0
        if cell[i][j] == '#':
            mat[i,j] = 1

col_del = np.all(mat == 0, axis=0)
row_del = np.all(mat == 0, axis=1)
col_index = np.where(col_del==True)
row_index = np.where(row_del==True)
#print(col_index)

res = np.delete(mat, row_index, axis=0)
res = np.delete(res, col_index, axis=1)
#print(res)
Hn = res.shape[0]
Wn = res.shape[1]

for i in range(Hn):
    ans = []
    for j in range(Wn):
        if res[i,j] == 0:
            ans.append('.')

        if res[i,j] == 1:
            ans.append('#')
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

H, W = (int(i) for i in input().split())

A = [["" for i in range(W)] for j in range(H)]

for i in range(H):
    tmp = list(input())
    for j in range(W):
        A[i][j] = tmp[j]

hlist = []
wlist = []

for i in range(H):
    if len(set(A[i])) == 1:
        hlist.append(i)

for j in range(W):
    tmp = []
    for i in range(H):
        tmp.append(A[i][j])
    if len(set(tmp)) == 1:
        wlist.append(j)

# print(hlist)
# print(wlist)

for i in hlist:
    for j in range(W):
        A[i][j] = 0

for j in wlist:
    for i in range(H):
        A[i][j] = 0

for i in range(H):
    while True:
        if 0 in A[i]:
            A[i].remove(0)
        else:
            break

while True:
    if [] in A:
        A.remove([])
    else:
        break

for li in A:
    print("".join(li))

Submission status: Wrong Answer

Solution code:
import numpy as np

H,W=map(int,input().split())
a=np.zeros((H,W))
for i in range(H):
    tmp = input()
    for j in range(W):
        if tmp[j] == "#":
            a[i][j]=1

tmp=[]
for i in range(H):
    if np.sum(a[i])==0:
        tmp.append(i)
a = np.delete(a,tmp,0)

h=len(tmp)

a = a.T

tmp=[]
for i in range(W):
    if np.sum(a[i])==0:
        tmp.append(i)
a = np.delete(a,tmp,0)
               
a = a.T

w = len(tmp)

ans = list(a)

print(a)
for i in range(H-h):
    tmp=a[i]
    for j in range(W-w):
        if tmp[j] == 1:
            print("#", end="")
        else:
            print(".", end="")
    print()

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
a = [[] for i in range(0,h)]
for i in range(0,h):
    A = list(input())
    a[i].extend(A)

hlist = []
for i in range(0,h):
    for j in range(1,w):
        if a[i][j-1] !=  a[i][j]:
            break
        if j == w-1:
            hlist.append(i)
wlist = []
for j in range(0,w):
    for i in range(1,h):
        if a[i-1][j] !=  a[i][j]:
            break
        if i == h-1:
            wlist.append(j)

b = 0
for i in hlist:
    a.pop(i-b)
    b += 1
    h -= 1
b = 0
for j in wlist:
    for i in range(0,h):
        a[i].pop(j-b)
    b += 1
    w -= 1

for i in range(0,h):
    for j in range(0,w):
        if j < w-1:
            print(a[i][j],end="")
        else:
            print(a[i][j])

Submission status: Wrong Answer

Solution code:
import sys

aa = input().split()
h = int(aa[0])
w = int(aa[1])
a = list()
for _ in range(h):
    a.append(list(input().strip()))

r = [list() for _ in range(2)]

for i in range(len(a)):
    b = a[i][0]
    flag = True

    for j in range(1, len(a[i])):
        if a[i][j] != b:
            flag = False
            break

    if 1 < len(a[i]) and flag:
        r[0].append(i)

for i in range(len(a[0])):
    b = a[0][i]
    flag = True

    for j in range(1, len(a)):
        if a[j][i] != b:
            flag = False
            break

    if 1 < len(a) and flag:
        r[1].append(i)

for i in reversed(range(len(r[0]))):
    del a[r[0][i]]

for i in reversed(range(len(r[1]))):
    for j in reversed(range(len(a))):
        del a[j][r[1][i]]

for i in range(len(a)):
    for j in range(len(a[i])):
        sys.stdout.write(a[i][j])

    sys.stdout.write('\n')

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
l=[]
for i in range(h):
    l.append(list(input()))
i=0
while i<len(l):
    for j in range(len(l[0])):
        if l[i][j]!='.':
            break
    else:
        del(l[i])
    i+=1

i=0    

while i<len(l[0]):
    for j in range(len(l)):
        if  l[j][i]!='.':
            break
    else:
        for k in range(len(l)):
            del l[k][i]
    i+=1
i=0
for i in range(len(l)):
    s=''
    for j in range(len(l[0])):
        s=s+l[i][j]
    print(s)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

line = input().split()
h = int(line[0])
w = int(line[1])

a = []
hr = []
for hi in range(h):
    line = list(input())
    if len(set(line))!=2:
        hr.append(hi)
    a.append(line)


wr = []
wi = 0
for line in zip(*a):
    if len(set(line))!=2:
        wr.append(wi)
    wi += 1

for hi in range(h):
    if hi in hr:
        continue
    for wi in range(w):
        if wi not in wr:
            print(a[hi][wi], end="")
    print("")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())

matrix = []

for i in range(h):
  row = list(input())
  if '#' not in row:
    continue
  else:
    matrix.append(row)

print(matrix)
removed_index = []

for i in range(len(matrix[0])):
  col = [row[i] for row in matrix]
  if '#' not in col:
    removed_index.append(i)

removed_index.reverse()

for n in removed_index:
  for row in matrix:
  	del row[n]

for row in matrix:
  print(''.join(row))

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())

matrix = []

for i in range(h):
  row = list(input())
  if '#' not in row:
    continue
  else:
    matrix.append(row)

print(matrix)
removed_index = []

for i in range(len(matrix[0])):
  col = [row[i] for row in matrix]
  if '#' not in col:
    removed_index.append(i)

removed_index.reverse()

for n in removed_index:
  for row in matrix:
  	del row[n]

for row in matrix:
  print(' '.join(row))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
a = [input() for _ in range(H)]
is_end = False
while not is_end:
    for i, width in enumerate(a):
        if '#' in width:
            is_end = True
            continue
        is_end = False
        del a[i]
        break

    for i, height in enumerate(list(zip(*a))):
        if '#' in height:
            is_end = True
            continue
        is_end = False
        a = [a[j][:i]+a[j][i+1:] for j in range(len(a))]
        break

print(*a, sep="\n")

Submission status: Wrong Answer

Solution code:
H, W = input().split(" ")
H = int(H)
W = int(W)
table = []
for i in range(H):
    table.append(list(input()))

i = 0
while i < H:
    if '#' not in table[i]:
        del table[i]
        H -= 1
    i = i + 1

table_t = [list(x) for x in zip(*table)]

i = 0
while i < W:
    if '#' not in table_t[i]:
        del table_t[i]
        W -= 1
    i = i + 1

table = [list(x) for x in zip(*table_t)]

for i in range(H):
    print("".join(table[i]))

Submission status: Wrong Answer

Solution code:
import sys

aa = input().split()
h = int(aa[0])
w = int(aa[1])
a = list()
for _ in range(h):
    a.append(list(input().strip()))

r = [list() for _ in range(2)]

for i in range(len(a)):
    b = a[i][0]
    flag = True

    for j in range(1, w):
        if a[i][j] != b:
            flag = False
            break

    if flag:
        r[0].append(i)

for i in range(len(a[0])):
    b = a[0][i]
    flag = True

    for j in range(1, len(a)):
        if a[j][i] != b:
            flag = False
            break

    if flag:
        r[1].append(i)

for i in reversed(range(len(r[0]))):
    del a[r[0][i]]

for i in reversed(range(len(r[1]))):
    for j in reversed(range(len(a))):
        del a[j][r[1][i]]

for i in range(len(a)):
    for j in range(len(a[i])):
        sys.stdout.write(a[i][j])

    sys.stdout.write('\n')

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
grid = []
for i in range(H):
    row = list(input())
    grid.append(row)
while True:
    r_change = False
    for q in range(len(grid)):
        if "#" not in grid[q]:
            del grid[q]
            r_change = True
            break
    if not r_change:
        break
while True:
    c_change = False
    for k in range(len(grid[0])):
        if "#" not in [row[k] for row in grid]:
            grid = [[row[p] for p in range(len(row)) if p != k] for row in grid]
            c_change = True
            break
    if not c_change:
        break
print(grid)

Submission status: Wrong Answer

Solution code:
import sys

aa = input().split()
h = int(aa[0])
w = int(aa[1])
a = list()
for _ in range(h):
    a.append(list(input().strip()))

r = [list() for _ in range(2)]

for i in range(len(a)):
    b = a[i][0]
    flag = True

    for j in range(1, w):
        if a[i][j] != b:
            flag = False
            break

    if flag:
        r[0].append(i)

for i in range(len(a[0])):
    b = a[0][i]
    flag = True

    for j in range(1, len(a)):
        if a[j][i] != b:
            flag = False
            break

    if flag:
        r[1].append(i)

for i in reversed(range(len(r[0]))):
    del a[r[0][i]]

for i in reversed(range(len(r[1]))):
    for j in range(len(a)):
        del a[j][r[1][i]]

for i in range(len(a)):
    for j in range(len(a[i])):
        sys.stdout.write(a[i][j])

    sys.stdout.write('\n')

Submission status: Wrong Answer

Solution code:
import sys
H, W = map(int, input().split())

grid = []
dot_h = []
sharp_h = []
dot_w = []
sharp_w = []

for h in range(H):
    line = input()
    line = line[:W]
    grid.append(line)
    if line.count('.') == W:
        dot_h.append(h)
    if line.count('#') == W:
        sharp_h.append(h)
for w in range(W):
    dot_c = 0
    sharp_c = 0
    for h in range(H):
        if grid[h][w] == '.':
            dot_c += 1
        if grid[h][w] == '#':
            sharp_c += 1
    if dot_c == H:
        dot_w.append(w)
    if sharp_c == H:
        sharp_w.append(w)
    
for h in range(H):
    if h in dot_h or h in sharp_h:
        continue
    for w in range(W):
        if w in dot_w or w in sharp_w:
            continue
        # print(grid[h][w], end="")
        sys.stdout.write(grid[h][w])
    print('')

Submission status: Wrong Answer

Solution code:
h, w = input().split()
h = int(h)
w = int(w)
for i in range(h):
    s = input()
    if(s != '.' * w):
        print(s)

Submission status: Wrong Answer

Solution code:
n,m = map(int, raw_input().split())
mat = []
for i in xrange(n):
    mat.append(list(raw_input()))

l = [[0 for i in xrange(m)] for j in xrange(n)]

for i in xrange(n):
    flag = 0
    for j in xrange(1,m):
        if mat[i][j] != mat[i][0]:
            flag = 1
    if flag:
        for j in xrange(m):
            l[i][j] = 1


for i in xrange(m):
    flag = 0
    for j in xrange(1,n):
        if mat[j][i] != mat[0][i]:
            flag = 1

    if not flag:
        for j in xrange(n):
            l[j][i] = 0



for i in xrange(n):
    s = ''
    for j in xrange(m):
        if l[i][j]:
            s += mat[i][j]
    if s != '':
        print s

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().strip().split(" "))

row = []
for i in range(H):
    line = input()
    if line.count(".") == W:
        continue
    row.append(line)

print(row)
row_count = len(row)
ans = [[] for i in range(row_count)]
for i in range(W):
    tmp = []
    for j in range(row_count):
        tmp.append(row[j][i])
    if tmp.count(".") == row_count:
        continue
    else:
        for index, c in enumerate(tmp):
            ans[index].append(c)
for i in ans:
    print("".join(i))

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split(" "))

def whitel(gyo):
    ans=0
    for i in range(len(gyo)):
        if gyo[i]=="#":
            ans=1
            break
    return ans

A=[]
for i in range(H):
    gyo=input()
    if whitel(gyo)==1:
        A.append(gyo)

for i in range(len(A)):
    print(A[i])

Submission status: Wrong Answer

Solution code:
import numpy as np
import math


H, W = map(int, input().split())

A = np.zeros((H, W), dtype=int)

for h in range(H):
    ah = input()
    for w in range(W):
        if ah[w] == '.':
            A[h][w] = 0
        else:
            A[h][w] = 1

# print(A)
remH = []
remW = []
            
for h in range(H):
    if all(A[h] == 0):
        remH.append(h)
for w in range(W):
    if all(A[:,w] == 0):
        remW.append(w)

# print(remH, remW)
        
ret = []

for h in range(H):
    if h in remH:
        continue
    hlist = []
    for w in range(W):
        if w in remW:
            continue
        # print(h)
        # print(w)
        # print(A[h][w])
        hlist.append(A[h][w])
    ret.append(hlist)

# print(ret)

retH = H - len(remH)
retW = W - len(remW)

print(retH, retW)
for x in range(retH):
    for y in range(retW):
        if ret[x][y] == 0:
            print('.', end='')
        else:
            print('#', end='')            
    print()

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[]
l=set()
for i in range(h):
  a=list(input())
  if set(a) != set("."):
    s.append(a)
    for j in range(w):
      if a[j]=="#":
        l|={j}
for i in s:
  p=""
  for j in l:
    p+=i[j]
  print(p)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
a = [input() for _ in range(H)]
is_end = False
while not is_end:
    flag = False
    for i, width in enumerate(a):
        if '#' in width:
            is_end = True
            continue
        flag = True
        is_end = False
        break
    if flag:
        del a[i]
    flag = False
    for i, height in enumerate(list(zip(*a))):
        if '#' in height:
            is_end = True
            continue
        flag = True
        is_end = False
        break
    if flag:
        a = [a[j][:i]+a[j][i+1:] for j in range(len(a))]
print(*a, sep="\n")

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
a = []
for i in range(h):
   tmp = input()
   a.append(tmp)

for i in range(h):
   for j in range(w):
      row = [x.count('.') for x in a]
      a = [x for x, k in zip(a, row) if k < len(x)]

      b = [list(x) for x in zip(*a)]
      line = [x.count('.') for x in b]
      b = [x for x, k in zip(b, line) if k < len(x)]
      a = [list(x) for x in zip(*b)]

for i in range(len(a)):
   for j in range(len(a[i])):
      print(a[i][j], end='')
   print()

Submission status: Time Limit Exceeded

Solution code:
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')

Submission status: Time Limit Exceeded

Solution code:
# Q2
H, W = map(int, input().split())
a = [[c for c in input()] for _h in range(H)]

compressed = True
while compressed:
    compressed = False
    for h in range(H):
        if '#' not in a[h]:
            for w in range(W):
                a[h][w] = ''
                compressed = True
    for w in range(W):
        if '#' not in [p[w] for p in a]:
            for h in range(H):
                a[h][w] = ''
                compressed = True

for h in range(H):
    line = ''.join(a[h])
    if line:
        print(''.join(a[h]))

Submission status: Time Limit Exceeded

Solution code:
# Q2
H, W = map(int, input().split())
a = [[c for c in input()] for _h in range(H)]

compressed = False
while not compressed:
    compressed = False
    for h in range(H):
        if '#' not in a[h]:
            for w in range(W):
                a[h][w] = ''
                compressed = True
    for w in range(W):
        if '#' not in [p[w] for p in a]:
            for h in range(H):
                a[h][w] = ''
                compressed = True

for h in range(H):
    line = ''.join(a[h])
    if line:
        print(''.join(a[h]))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
S, U = [], []
for _ in range(H):
    s = list(input())
    if "#" in s: S.append(s)
T = list(zip(*S))
for i in range(W):
    if "#" in T[i]: U.append(T[i])
res = []
for t in zip(*U):
    res.append("".join(t))
print("\n".join(res))

Submission status: Accepted

Solution code:
def main():
    h, w = list(map(int, input().split()))
    board = []
    safe_h = set()
    safe_w = set()
    for i in range(h):
        board.append(list(input()))
    for i in range(h):
        for j in range(w):
            if board[i][j] == '#':
                safe_h.add(i)
                safe_w.add(j)
    for i in safe_h:
        for j in safe_w:
            print(board[i][j], end='')
        print()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = [list(input()) for i in range(H)]
a = [x for x in a if '#' in x]
aT = list(zip(*a))
aT = [x for x in aT if '#' in x]
a = list(zip(*aT))
for i in a:
    print(''.join(i))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [list(input()) for i in range(h)]
delrow = []
delline = []
for i in range(w):
  whiteline = 0
  for j in range(h):
    if a[j][i] == ".":
      whiteline += 1
    if whiteline == h:
      delline.append(i)
for i in range(h):
  whiterow = 0
  for j in range(w):
    if a[i][j] == ".":
      whiterow += 1
    if whiterow == w:
      delrow.append(i)
for i in range(h):
  if i in delrow:
    continue
  else:
    ans = ""
    for j in range(w):
      if j in delline:
        continue
      else:
        ans += a[i][j]
  print(ans)

Submission status: Accepted

Solution code:
from typing import List


def answer(h: int, w: int, a: List[str]) -> List[str]:
    for i in range(2):
        white_line = '.' * w
        loop = a.count(white_line)
        for _ in range(loop):
            a.remove(white_line)
        a = [''.join(line) for line in (zip(*a))]
        if i == 0:
            w = h - loop

    return a


def main():
    h, w = map(int, input().split())
    a = [input() for _ in range(h)]
    for i in answer(h, w, a):
        print(i)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

def main():

    H,W = map(int,input().split())
    A = [[0 if s == "." else 1 for s in list(input())] for _ in range(H)]

    for i in reversed(range(H)):
        if sum(A[i]) == 0:
            A.pop(i)

    A = np.array(A).T.tolist()
    for i in reversed(range(W)):
        if sum(A[i]) == 0:
            A.pop(i)
    A = np.array(A).T.tolist()

    for i in range(len(A)):
        print("".join(["." if i == 0 else "#" for i in A[i]]))

main()

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
import sys
h,w = ma()
t="."*w
ls=[]
for i in range(h):
    s=input()
    if s!=t:
        ls.append(s)

l = len(ls)
t="."*l
ans = [[] for i in range(l)]
for i in range(w):
    f=False
    for j in range(l):
        if ls[j][i]=="#":
            f=True
    if f:
        for j in range(l):
            ans[j].append(ls[j][i])
for a in ans:
    print("".join(a))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
tizu = [input() for _ in range(h)]
h_s = [False for _ in range(h)]
w_s = [False for _ in range(w)]
for i in range(h):
  for j in range(w):
    if tizu[i][j] == "#":
      h_s[i] = True
      w_s[j] = True

for i in range(h):
  if not h_s[i]:
    continue
  row = ""
  for j in range(w):
    if w_s[j]:
      row += tizu[i][j]
  print(row)

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = []
hh = 0
for _ in range(h):
  x = [xx for xx in input()]
  if x.count("#") > 0:
    a.append(x)
    hh += 1
b = []

count = 0
if hh > 1:
  wlist = []
  for i in range(w):
    for j in range(hh):
      b.append(a[j][i])
    if b.count("#") == 0:
      wlist.append(i)
    b = []
  for k in wlist:
    for l in range(hh):
      a[l].pop(k-count)
    count += 1
  for m in range(len(a)):
    print("".join(a[m]))
else:
  a = list(*a)
  ans = [aa for aa in a if aa == "#"]
  print("".join(ans))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = []
for i in range(H):
  S = input()
  f = 0
  for j in range(W):
    if S[j] == "#":
      f = 1
      break
  if f == 1:
    A.append(S)
H = len(A)
ANS = ["" for i in range(H)]
for j in range(W):
  f = 0
  for i in range(H):
    if A[i][j] == "#":
      f = 1
      break
  if f == 1:
    for i in range(H):
      ANS[i] += A[i][j]
for i in range(H):
  print(ANS[i])

Submission status: Accepted

Solution code:
H, W = map(int, input().split())

L, side, ver = [], [], []

for i in range(H):
    a = list(input())
    L.append(a)

def check(n, inlist, outlist):
    """[summary]
    全て白マスの行を削除する
    転置行列を返すので列の判定にも対応可能
    Args:
        n ([type]): 配列サイズ
        inlist ([type]): 入力する二次元配列
        outlist ([type]): 出力する二次元配列

    Returns:
        [list]: 不要な要素を削除して転置して返す
    """    
    for i in range(n):
        if ('#' in inlist[i]) == True:
            outlist.append(inlist[i])
    return list(map(list, zip(*outlist)))

side = check(H, L, side)
ver = check(len(side), side, ver)

for i in range(len(ver)):
    print(''.join(ver[i]))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())

L, side, ver = [], [], []

for i in range(H):
    a = list(input())
    L.append(a)

for i in range(H):
    if ('#' in L[i]) == True:
        side.append(L[i])

side = list(map(list, zip(*side)))

for i in range(len(side)):
    if ('#' in side[i]) == True:
        ver.append(side[i])

ver = list(map(list, zip(*ver)))

for i in range(len(ver)):
    print(''.join(ver[i]))

Submission status: Accepted

Solution code:
import copy
h,w = map(int,input().split())
a = [input() for  i in range(h)]
index = 1
ans = copy.copy(a)
for i in range(h):
    bool = True
    for j in range(w):
        if a[i][j] == '#':
            bool = False
    if bool:
        index -= 1
        del ans[index + i]
ans_1 = copy.copy(ans)
key = 1
for i in range(w):
    bool = True
    for j in range(h - (1 - index)):
        if ans[j][i] == '#':
            bool = False
    if bool:
        key -= 1
        for k in range(h - (1 - index)):
            ans_1[k] = ans_1[k][:(i + key)] + ans_1[k][(i + key + 1):]
for i in range(len(ans_1)):
    print(ans_1[i])

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [''] * h
for i in range(h):
	a[i] = input()

row = [False] * h
col = [False] * w
for i in range(h):
	for j in range(w):
		if a[i][j] == '#':
			row[i] = True
			col[j] = True

for i in range(h):
	if row[i]:
		for j in range(w):
			if col[j]:
				print(a[i][j], end = '')
		print()

Submission status: Accepted

Solution code:
h, w = (int(i) for i in input().split())
list_a = [input() for s in range(0, h)]
list_tmp = []
for i in range(0, h):
    for j in range(0, w):
        if list_a[i][j] == '#':
            list_tmp.append(list(list_a[i]))
            break
# 転置... https://note.nkmk.me/python-list-transpose/　参照
list_tmp_t = [list(x) for x in zip(*list_tmp)]
list_tmp2 = []
for i in range(0, len(list_tmp_t)):
    for j in range(0, len(list_tmp_t[i])):
        if list_tmp_t[i][j] == '#':
            list_tmp2.append(list(list_tmp_t[i]))
            break
# 転置... https://note.nkmk.me/python-list-transpose/　参照
list_ans = [list(x) for x in zip(*list_tmp2)]
for i in range(0, len(list_ans)):
    print("".join(list_ans[i]))

Submission status: Accepted

Solution code:
import numpy as np

h, w = map(int, input().split())
a = np.array([list(input()) for _ in range(h)])

for i in range(h):
    if np.count_nonzero(a[i] == '#') == 0:
        a[i] = 'x'
for i in range(w):
    if np.count_nonzero(a[:, i] == '#') == 0:
        a[:, i] = 'x'

for i in range(h):
    if res := ''.join(filter(lambda x: x != 'x', a[i])):
        print(res)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

h, w = map(int, input().split())
graph = []
for _ in range(h):
    r = input().strip()
    if set(r) == {'.'}:
        continue
    graph.append(r)

transpose_graph = [[0] * len(graph) for _ in range(w)]
for i in range(len(graph)):
    for j in range(w):
        transpose_graph[j][i] = graph[i][j]

graph = []
for i in range(w):
    if set(transpose_graph[i]) == {'.'}:
        continue
    graph.append(transpose_graph[i])

transpose_graph = [[0] * len(graph) for _ in range(len(graph[0]))]
for i in range(len(graph)):
    for j in range(len(graph[0])):
        transpose_graph[j][i] = graph[i][j]

for r in transpose_graph:
    print(''.join(r))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[input() for i in range(h)]
row=[False]*h
col=[False]*w
for i in range(h):
  for j in range(w):
    if a[i][j]=="#":
      row[i]=True
      col[j]=True
for i in range(h):
  for j in range(w):
    if row[i]==True and col[j]==True:
      print(a[i][j],end="")
  if row[i]:
    print()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a_list = [list(input()) for _ in range(H)]
dot_cnt = [sum([a == '.' for a in a_col]) for a_col in a_list]
exist_idx = [i for i, num in enumerate(dot_cnt) if num != W]
st = set(range(W))
for i in exist_idx:
    dot_idx = [i for i, a in enumerate(a_list[i]) if a == '.']
    st = st & set(dot_idx)
for i in exist_idx:
    print(''.join([a for i, a in enumerate(a_list[i]) if i not in st]))

Submission status: Accepted

Solution code:
# import sys
# input = sys.stdin.readline
import collections
import itertools

def main():
    h, w = input_list()
    maze = [list(input()) for _ in range(h)]
    ans = []
    blacks = [False] * w
    for m in maze:
        for i, v in enumerate(m):
            if v == "#":
                blacks[i] = True
    for m in maze:
        f = True
        new_row = []
        for i, b in enumerate(blacks):
            if b:
                new_row.append(m[i])
        for i, v in enumerate(new_row):
            if v == "#":
                f = False
                break
        if f:
            continue
        ans.append(new_row)
    for a in ans:
        print("".join(a))


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    H, W = LI()
    a = []
    excrow = set()
    exccol = set()
    for _ in range(H):
        a.append(S())
    for row in range(H):
        all_white = True
        for c in a[row]:
            if c == '#':
                all_white = False
                break
        if all_white:
            excrow.add(row)

    for col in range(W):
        all_white = True
        for r in range(H):
            if a[r][col] == '#':
                all_white = False
                break
        if all_white:
            exccol.add(col)

    newA = []
    for row in range(H):
        if row in excrow:
            continue
        newA.append(a[row])

    newnewA = []
    for row in range(len(newA)):
        string = ''
        for col in range(W):
            if col in exccol:
                continue
            string += newA[row][col]
        newnewA.append(string)
    print('\n'.join(newnewA))


main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
H, W = map(int, input().split())
grid = []
for _ in range(H):
    grid.append(list(input().strip()))

h_set = set()
for i in range(H):
    flag = True
    for j in range(W):
        if grid[i][j] == "#":
            flag = False
            break
    if flag:
        h_set.add(i)

w_set = set()
for j in range(W):
    flag = True
    for i in range(H):
        if grid[i][j] == "#":
            flag = False
            break
    if flag:
        w_set.add(j)

for i in range(H):
    if i in h_set:
        continue
    for j in range(W):
        if j in w_set:
            continue
        print(grid[i][j], end="")
    print("")

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
for i in range(h):
  s = input()
  if s.count('#') > 0:
    a.append(s)

b = [0 for i in range(w)]
for gl in a:
  for i in range(w):
    if gl[i] == '#':
      b[i] += 1
for gl in a:
  v = ''
  for i in range(w):
    if b[i] > 0:
      v += gl[i]
  print (v)

Submission status: Accepted

Solution code:
import numpy as np

h, w = map(int,input().split())

maze = []
for i in range(h):
    row = list(input())
    if "#" in row:
        maze.append(row)
        
maze = np.array(maze)
maze = np.rot90(maze)

ans = []
for row in maze:
    if "#" in row:
        ans.append(row)
        
ans = np.rot90(ans, -1)

for r in ans:
    print("".join(r))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
A=[list(input()) for i in range(h)]
answ=[]
ansh=[]
for i in range(h):
  if not all([a=="." for a in A[i]]):
    answ.append(i)
for j in range(w):
  if not all([A[i][j]=="." for i in range(h)]):
    ansh.append(j)
for i in answ:
  for j in ansh:
    print(A[i][j],end="")
  print("")