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: Accepted

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def IS():
    return input().split()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2)
    found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()
 
def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a
 
show_flg=False
show_flg=True
 
ans=0

h,w=LI()
t=[]
for i in range(h):
    s=input()
    if s=='.'*w:
        continue
    t+=[s]

u=[[0]*len(t) for i in range(w)]
for i in range(len(t)):
    for j in range(w):
        u[j][i]=t[i][j]

ans=[]
for x in u:
    if x.count('#')==0:
        0
    else:
        ans+=[x]

ANS=[[0]*len(ans) for i in range(len(ans[0]))]
for i in range(len(ans)):
    for j in range(len(ans[0])):
        ANS[j][i]=ans[i][j]
for i in ANS:
    print(''.join(i))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
m=[]
for _ in range(h):
  temp = input()
  if temp.count("#") == 0:
    continue
  m.append(temp)

ku=[]
for i in range(w):
  for j in m:
    if j[i] == "#":
      break
  else:
    ku.append(i)

k = list(set([i for i in range(w)]) - set(ku))
for i in m:
  temp=""
  for j in k:
    temp += i[j]
  print(temp)

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
A = []
hh = H
for y in range(H):
  ain = input()
  if "#" in ain:
    A.append(ain)
  else:
    hh -= 1
d = [ 0 for _ in range(W)]
for x in range(W):
  for y in range(hh):
    if A[y][x] == "#":
      break
  else:
    d[x] = 1
for y in range(hh):
  for x in range(W):
    if d[x] == 0:
        print(A[y][x], end="")
  print("")

Submission status: Accepted

Solution code:
def main():
    H, W = map(int, input().split(" "))
    grids = []
    for _ in range(H):
        line = input()
        if "#" in line:
            grids.append([l for l in line])
        else:
            continue
    for i in range(W):
        tmp = 0
        for grid in grids:
            if grid[i] == ".":
                tmp += 1
        if tmp == len(grids):
            for grid in grids:
                grid[i] = ""
    for grid in grids:
        print("".join(grid))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
H_W = list(map(int,input().split()))
H = H_W[0]
W = H_W[1]
b = [[0 for i in range(W)] for j in range(H)]
a = [[str(c) for c in l.strip()] for l in sys.stdin]

# .を0に, #を1にした新しい配列bを作る
for i in range(H):
    for j in range(W):
        if a[i][j] == '#':
            b[i][j] = 1

# 列と行ごとにすべて0のものを探す
w = [0] * W
h = [0] * H
for i in range(H):
    for j in range(W):
        h[i] = h[i] + b[i][j]
        w[j] = w[j] + b[i][j]

#print(h)
#print(w)
# 全ての要素が0の列と行を削除する
i = 0
c = 0
j = 0
for i in range(H):
    if h[i] == 0:
        del a[j]
        H = H - 1
        j = j - 1
    j = j + 1
#print(a)

k = 0
for i in range(W):
    if w[i] == 0:
        for j in range(H):
            del a[j][k]
        W = W - 1
        k = k - 1
    k = k + 1
#print(a)
# 答え
for i in range(H):
    flag = 0
    for j in range(W):
        if flag == 0:
            ans = a[i][j]
            flag = 1
        else:
            ans = ans + a[i][j]
    print(ans)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
l=[list(input()) for _ in range(h)]
l=[x for x in l if '#' in x]
l=[x for x in zip(*l) if '#' in x]
for i in zip(*l):
	print(''.join(i))

Submission status: Accepted

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

for i in range(H):
    a[i]=input()
    
ans=[[0]*W for _ in range(H)]

for i in range(H):
    if a[i]=="."*W:
        continue
    else:
        for j in range(W):
            if a[i][j]==".":
                ans[i][j]=1
            else:
                ans[i][j]=2

        
        
for j in range(W):
    if 2 in [row[j] for row in ans]:
        continue
    else:
        for i in range(H):
            ans[i][j]=0
        
for i in range(H):
    temp=""
    for j in range(W):
        if ans[i][j]==1:
            temp+="."
        elif ans[i][j]==2:
            temp+="#"
    if temp!="":
        print(temp)

Submission status: Accepted

Solution code:
def initSquare(H, W):
    square = []
    for r in range(H):
        row = []
        row_string = input()
        for letter in row_string:
            row.append(letter)
        square.append(row)
    return square

def rowChecker(square):
    delete_row_indexes = []
    for i, row in enumerate(square):
        if "#" not in row:
            delete_row_indexes.append(i)            
    return delete_row_indexes

def columnChecker(square):
    delete_column_indexes = []
    for c in range(W):
        column = []
        for r in range(H):
            column.append(square[r][c])
        if "#" not in column:
            delete_column_indexes.append(c)            
    return delete_column_indexes

def generateNewSquare(square, delete_row_indexes,delete_column_indexes):
    new_square = []
    for r, row in enumerate(square):
        if r not in delete_row_indexes:
            new_row = []
            for c, column in enumerate(row):
                if c not in delete_column_indexes:
                    new_row.append(column)
            new_square.append(new_row)
    return new_square

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

square = initSquare(H, W)
delete_row_indexes = rowChecker(square)
delete_column_indexes = columnChecker(square)
new_square = generateNewSquare(square, delete_row_indexes,delete_column_indexes)

for row in new_square:
    row_string = ''.join(row)
    print(row_string)

Submission status: Accepted

Solution code:

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

grid = []
cols = [True for _ in range(W)]
rows = [True for _ in range(H)]

for _ in range(H):
    tmp = input()
    grid.append(tmp);
    
for i in range(H):
    if grid[i].count('.') == W:
        rows[i] = False        


for i in range(W):
    count = 0
    for j in range(H):
        if grid[j][i] == '.':
            count += 1
    if count == H:
        cols[i] = False

for i in range(H):
    if rows[i]:
        for j in range(W):
            if cols[j]:
                print(grid[i][j], end="")
        print()

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
 
h = []
w_tmp = [0 for i in range(W)]
A =[]
for i in range(H):
  a = input()
  A.append(a)
  if "#" in a:
    h.append(i)
  for j in range(W):
    if a[j] == "#":
      w_tmp[j]+=1
w =[]
for j in range(W):
  if w_tmp[j] > 0:
    w.append(j)
for i in h:
  for j in w:
    print(A[i][j],end="")
  print("")

Submission status: Accepted

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

grid = [list(input()) for _ in range(H)]
l = [x for x in grid if "#" in x]
l = [x for x in zip(*l) if "#" in x]

for i in zip(*l):
    print("".join(i))

Submission status: Accepted

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

g = []
for i in range(h):
    g.append(input())

g2 = []
for line in g:
    if '#' in line:
        g2.append(line)

g3 = []
for _ in g2: g3.append([])

for j in range(w):
    if any([g2[i][j] == '#' for i in range(len(g3))]):
        for i in range(len(g3)):
            g3[i].append(g2[i][j])

for line in g3:
    print(''.join(line))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[[j for j in input()] for i in range(h)]
b=[x for x in a if "#" in x]
c=zip(*[y for y in zip(*b) if "#" in y])
for d in c:
  print("".join(d))

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
L=[list(input()) for _ in range(H)]
for _ in range(H+W):
    ans=[]
    res=[]
    l=[]
    for s in L:
        if '#' in s:
            l.append(s)
    for z in zip(*l):
        if '#' in z:
            res.append(z)
    for z in zip(*res):
        ans.append(list(z))
    L=ans.copy()
for t in L:
  print(''.join(t))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[list(input()) for _ in range(h)]
a=[x for x in a if "#" in x]
a=[x for x in zip(*a) if "#" in x]
a=[list(x) for x in zip(*a)]
for b in a:
  print("".join(b))

Submission status: Accepted

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

squares=[]

for i in range(H):
    squares.append(list(input()))

# rows
    
for i in range(H-1,-1,-1):
    if '#' not in squares[i]:
        del squares[i]
        
# columns
check_col =[]  
    
for j in range(W):
    flag=True
    for i in range(len(squares)):
        if squares[i][j] == '#':
            flag = False
    if flag:
        check_col.append(j)

check_col.sort(reverse=True)

for j in check_col:
    for i in range(len(squares)):
        del squares[i][j]
        
# print

for i in range(len(squares)):
    print(''.join(squares[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:

import numpy as np

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

a = [list(str(input())) for i in range(H)]
b = []

for i in range(H):
    for j in range(W):
        if a[i][j]!=".":
            b.append(a[i])
            break

del_targets = []
b_arr = np.array(b)

#print(b_arr)
            
for j in range(W):
    #print(b_arr[:,j])
    if b_arr[:,j].tolist().count(".") == len(b_arr[:,j].tolist()):
        del_targets.append(j)
        
ans = np.delete(b_arr, del_targets, 1)

for i in range(len(ans)):
    print(str(''.join(ans[i,:])))

Submission status: Accepted

Solution code:
# 一日かかった．特に後段の’#’一つのみの特殊ケース？になかなか気づけなかった．

h,w = map(int, input().split())
l = [list(list(input())) for i in range(h)]
W = []
for j in range(w):
    for k in range(h-1):
        if l[k][j] == l[k+1][j] == '.':
            continue
        else:
            break
    else:
        W.append(j)
W = sorted(W, reverse=True) #後で消す列のリスト、降順

H = []
for m in range(h):
    if set(l[m]) == {'.'}:
        H.append(m)
H = sorted(H, reverse=True) #後で消す行のリスト、降順

if l == [['#']]: # なぜか'#'１つのみの場合のみ特殊ケース
    print('#')
else:
    for p in range(len(W)):
        for q in range(h):
            del l[q][W[p]]
    
    for r in H:
        del l[r]
    
    for s in l:
        print(''.join(s))

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
l = [list(list(input())) for i in range(h)]
W = []
for j in range(w):
    for k in range(h-1):
        if l[k][j] == l[k+1][j] == '.':
            continue
        else:
            break
    else:
        W.append(j)
W = sorted(W, reverse=True)
#print(W) #後で消す列

H = []
for m in range(h):
    if set(l[m]) == {'.'}:
        H.append(m)
H = sorted(H, reverse=True)
#print(H)

if l == [['#']]:
    print('#')
else:
    for p in range(len(W)):
        for q in range(h):
            del l[q][W[p]]
    #print(l)
    
    for r in H:
        del l[r]
    #print(l)
    
    for s in l:
        print(''.join(s))

Submission status: Accepted

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

a = list(zip(*[i for i in a if "#" in i]))
a = list(zip(*[i for i in a if "#" in i]))

for i in a:
    print("".join(i))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
s = []
wl = [0]*w
hl = [0]*h
for _ in range(h):
  s.append(input())
for i in range(h):
  if s[i].count("#") == 0:
    hl[i] = 1
for j in range(w):
  cnt = 0
  for i in range(h):
    if s[i][j] == "#":
      break
    cnt += 1
  if cnt == h:
    wl[j] = 1
ans=[]
for i in range(h):
  tmp =""
  if hl[i] == 0:
    for j in range(w):
      if wl[j] == 0:
        tmp += s[i][j]
    ans.append(tmp)
for x in ans:
  print(x)

Submission status: Accepted

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

for i in range(h):
    line = input()
    for j in range(w):
        a[i][j] = line[j]

delete_row = []
for i in range(h):
    chk = True
    for j in range(w):
        if a[i][j] == '#':
            chk = False
            break
    if chk:
        delete_row.append(i)

for row in delete_row[::-1]:
    a.pop(row)

delete_col = []
for i in range(w):
    chk = True
    for j in range(h-len(delete_row)):
        if a[j][i] == '#':
            chk = False
            break
    if chk:
        delete_col.append(i)

for row in a:
    for col in delete_col[::-1]:
        row.pop(col)

for i in a:
    for j in i:
        print(j, end='')
    print()

Submission status: Accepted

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

a = [list(input()) for _ in range(H)]

h = [False]*H
w = [False]*W

for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            h[i] = True
            w[j] = True
for i in range(H):
    if h[i]:
        for j in range(W):
            if w[j]:
                print(a[i][j],end="")
        print()

Submission status: Accepted

Solution code:
import numpy as np

H,W=map(int,input().split())
a=[list(input()) for i in range(H)]
#a=np.array(a)
b=[]
c=[]
count1=0
count2=0
#print(a)
for i in range(H):
    l=a[i]
    #print(set(l),l[0])
    if not((len(set(l))==1)and(l[0]==".")):
        b.append(l)
        count1=count1+1
b=np.array(b)
b=b.T
b=b.tolist()
#print(b)
for i in range(W):
    l=b[i]
    #print(set(l),l[0])
    if not((len(set(l))==1)and(l[0]==".")):
        c.append(l)
        count2=count2+1
#print(c)
c=np.array(c)
c=c.T
c=c.tolist()
#print(c)
for i in c:print(*i,sep='')

Submission status: Accepted

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

ll = [list(input()) for _ in range(h)]
lh = [h for h in ll if '#' in h]
lw = zip(*[w for w in zip(*lh) if '#' in w])

for l in lw:
  print(''.join(l))

Submission status: Accepted

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

ll = [list(input()) for _ in range(h)]
ll = [s for s in ll if '#' in s]

lr = []
for i in range(w):
  if any(l[i] == '#' for l in ll):
    lr.append(i)

for l in ll:
  ans = ''
  for i in lr:
    ans += l[i]
  print(ans)

Submission status: Accepted

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

ll = []
for _ in range(h):
  s = input()
  if '#' in s:
    ll.append([s[i] for i in range(w)])

lr = []
for i in range(w):
  if any(l[i] == '#' for l in ll):
    lr.append(i)

for l in ll:
  ans = ''
  for i in lr:
    ans += l[i]
  print(ans)

Submission status: Accepted

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

ll = []
for _ in range(h):
  s = input()
  if s != '.'*w:
    ll.append([s[i] for i in range(w)])

lr = []
for i in range(w):
  if all(l[i] == '.' for l in ll):
    lr.insert(0, i)

for l in ll:
  for i in lr:
    l.pop(i)
  print(''.join(l))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = [input() for _ in range(H)]

h_check = [0] * H
w_check = [0] * W

for i in range(H):
  for j in range(W):
    if A[i][j] == ".":
      h_check[i] += 1
      w_check[j] += 1

h_check = list(map(lambda x: 1 - x // W, h_check))
w_check = list(map(lambda x: 1 - x // H, w_check))

for i in range(H):
  if h_check[i]:
    tmp = ""
    for j in range(W):
      if w_check[j]:
        tmp += A[i][j]
    print(tmp)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = [input() for _ in range(H)]

h_check = [0] * H
w_check = [0] * W

for i in range(H):
  flag = 0
  for j in range(W):
    if A[i][j] != ".":
      flag = 1
      break
  h_check[i] = flag

for j in range(W):
  flag = 0
  for i in range(H):
    if A[i][j] != ".":
      flag = 1
      break
  w_check[j] = flag

for i in range(H):
  if h_check[i]:
    tmp = ""
    for j in range(W):
      if w_check[j]:
        tmp += A[i][j]
    print(tmp)

Submission status: Accepted

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

black_h = []
black_w = []

a = []
for h in range(H):
  s = input()
  for si, sv in enumerate(list(s)):
    if sv == '#':
      black_h.append(h)
      black_w.append(si)
  a.append(list(s))

ans = []
for h in range(H):
  if h not in black_h:
    continue
  A = []
  for w in range(W):
    if w not in black_w:
      continue
    A.append(a[h][w])
  ans.append(A)
  
for v in ans:
  print(''.join(v))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
h,w = map(int,input().split())
a = []
for i in range(h):
    a.append(input())
row = []
col = []
for i in range(h):
    if a[i] == "."*w: row.append(i)
for j in range(w):
    flag = 0
    for i in range(h):
        if a[i][j] != ".": flag = 1
    if flag == 0:
        col.append(j)
#print(row,col)
for i in range(h):
    flag = 0
    if i in row:
        #print("y")
        flag = 1
    if flag == 0:
        for j in range(w):
            if j not in col: print(a[i][j],end="")
        print("")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

h,w = map(int,input().split())
a = []
dlrow = []
dlcol = []

efrow = list(range(h))
efcol = list(range(w))

# input
for i in range(h):
    a.append(input())

# row
for i in range(h):
    flg = True
    for j in range(w):
        if a[i][j] == '#':
            flg = False
    # delete this row
    if flg == True:
        dlrow.append(i)
        efrow.remove(i)

#print("dlrow =",dlrow)
#print("efrow =",efrow)

# column
for j in range(w):
    flg = True
    for i in range(h):
        if a[i][j] == '#':
            flg = False
    # delete this column
    if flg == True:
        dlcol.append(j)
        efcol.remove(j)

#print("dlcol =",dlcol)
#print("efcol =",efcol)

# print
for i in efrow:
    s = []
    s2 = []
    for j in efcol:
      s.append(a[i][j])
      s2 = "".join(s)
    print(s2)

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
vax = []
hax = []
a = [str(input()) for i in range(H)]
for i in range(H):
    for j in range(W):
        if a[i][j] == '#':
            if i not in vax:
                vax.append(i)
            if j not in hax:
                hax.append(j)
vax.sort()
hax.sort()       
for i in vax:
    for j in hax:
        b = a[i][j]
        print(b,end="")
    print("")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    H,W=map(int,input().split())
    A=[]
    for i in range(H):
        a=input()
        if a!='.'*W:
            A.append(a)
    ans=[[] for _ in range(len(A))]
    for i in range(W):
        f=False
        for j in range(len(A)):
            if A[j][i]=='#':
                f=True
                break
        if f:
            for j in range(len(A)):
                ans[j]+=A[j][i]
    for x in ans:
        print(''.join(x))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H, W = map(int,input().split())
HW = [str(input()) for i in range(H)]

i = 0
while len(HW) > i:
  if "#" not in HW[i]:
    HW.pop(i)
    i -= 1
  i += 1  
  #print(HW)  
#print(HW)
clear_w = [0] * W
for i in range(len(HW)):
  for j in range(W):
    x = HW[i][j]
    if x == "#":
      clear_w[j] = 1
#print(clear_w)
 
for i in range(len(HW)):
  HW[i] = [HW[i][j] for j in range(W) if clear_w[j] == 1]
  
#print(HW)      
for i in range(len(HW)):
  for j in range(len(HW[i])):
    if j != len(HW[i]) - 1:
      print(HW[i][j], end = "")
    else:
      print(HW[i][j])

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[]
allwhite_row=[]
allwhite_column=list(set([i for i in range(w)]))
for i in range(h):
    row=input()

    whitecolumn_index=row.find('.',0)
    whitecolumn=[]
    while(whitecolumn_index != -1):
        whitecolumn.append(whitecolumn_index)
        whitecolumn_index = row.find('.',whitecolumn_index+1)

    allwhite_column = list(set(allwhite_column) & set(whitecolumn))

    if(list(row).count('.')==w):
        allwhite_row.append(i)

    a.append(row)

for i in range(h):
    if(i not in allwhite_row):
        ans_i=[]
        for j in range(w):
            if(j not in allwhite_column):
                ans_i.append(a[i][j])
        print(''.join(ans_i))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
arr = list(list(input()) for _ in range(n))
rmv_row = [1] * n
rmv_col = [1] * m
for i in range(n):
    for j in range(m):
        if arr[i][j] == '#':
            rmv_row[i] = 0
            rmv_col[j] = 0
for i in range(n):
    if rmv_row[i] == 1:
        continue
    for j in range(m):
        if rmv_col[j] == 1:
            continue
        print(arr[i][j], end='')
    print()

Submission status: Accepted

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

H, W = map(int, input().split())
c = 0
b = []
for i in range(H):
    a = list(input())
    if a != ["." for _ in range(W)]:
        b.append(a)
    else:
        c += 1

b = np.array(b)
b_T = b.T

B = []
for i in range(W):
    if list(b_T[i]) != ["." for _ in range(H-c)]:
        B.append(b_T[i])
B = np.array(B)
ans = B.T
for i in range(len(ans)):
    print("".join(map(str, ans[i])))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
allwhite = [True]*W
M = []
for _ in range(H):
    s = input()
    if s.count('.')==W: continue
    M.append(s)
    for w,c in enumerate(s):
        allwhite[w] *= c=='.'
    

for s in M:
    for c,f in zip(s, allwhite):
        if not f: print(c, end='')
    print()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[]
for i in range(h):
  tmp=input()
  if len(tmp)!=tmp.count('.'):
    a.append(tmp)
  else:
    h-=1

b=[]
for i in range(w):
  cnt=0
  for j in range(h):
    if a[j][i]=='.':
      cnt+=1
  if cnt==h:
    b.append(0)
  else:
    b.append(1)

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

Submission status: Accepted

Solution code:
import numpy as np
h, w = map(int, input().split())
field = []
for _ in range(h):
    row = list(input())
    field.append(row)
field = np.array(field)


deleterow = []
deleteline = []
for i in range(field.shape[0]):
    if set(field[i,:])=={'.'}:
        deleterow.append(i)
for j in range(field.shape[1]):
    if set(field[:,j])=={'.'}:
        deleteline.append(j)

for i, row in enumerate(field):
    if i in deleterow:
        continue
    for j, val in enumerate(row):
        if j in deleteline:
            continue
        print(val, end='')
    print('')

Submission status: Accepted

Solution code:
H, W = [int(i) for i in input().split()]
maze = [list(input()) for _ in range(H)]
maze = [l for l in maze if "#" in l]
maze = list(zip(*maze))
maze = [l for l in maze if "#" in l]
maze = list(zip(*maze))
maze = ["".join(l) for l in maze]
print(*maze, sep="\n")

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
white_column = []
a = [list(input()) for _ in range(H)]

# Mark white columns
for j in range(W-1, -1, -1):
    flag = True

    for i in range(H):
        if a[i][j] != '.':
            flag = False
            break

    if flag:
        for i in range(H):
            a[i].pop(j)
        W -= 1

# Print line if it contains black grid
for i in range(H):
    flag = True

    for j in range(W):
        if a[i][j] == '.':
            continue
        else:
            flag = False
            break

    if flag:
        continue
    else:
        print(''.join(a[i]))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
l = [list(input()) for i in range(n)]
gyou = []
retsu = []
count = 0
for i in range(n):
    a = "."
    count = 0
    for j in range(m):
        if a == l[i][j]:
            count += 1
    if count != m:
        gyou.append(i)
for i in range(m):
    a = "."
    count = 0
    for j in range(n):
        if a == l[j][i]:
            count += 1
    if count != n:
        retsu.append(i)

for i in range(n):
    if i in gyou:
        for j in range(m):
            if j in retsu:
                if j == retsu[-1]:
                    print(l[i][j])
                else:
                    print(l[i][j],end="")

Submission status: Accepted

Solution code:
h, w = map(int,input().split())
aList = []
for i in range(h):
  aList.append(list(input()))
for i in range(h-1,-1,-1):
  if aList[i].count('#') == 0:
    aList.pop(i)

aList = list(zip(*aList))
for i in range(w-1,-1,-1):
  if aList[i].count('#') == 0:
    aList.pop(i)

aList = list(zip(*aList))

for i in aList:
  print(''.join(i))

Submission status: Accepted

Solution code:
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())

sys.setrecursionlimit(10 ** 9)


def main():
    H, W = MAP()
    A = [INPUT() for _ in range(H)]

    ans_H = []
    for y in range(H):
        for x in range(W):
            if A[y][x] == '#':
                ans_H.append(y)
                break

    ans_W = []
    for x in range(W):
        for y in range(H):
            if A[y][x] == '#':
                ans_W.append(x)
                break

    ans = ["" for _ in range(len(ans_H))]
    for i, h in enumerate(ans_H):
        for w in ans_W: ans[i] += A[h][w]

    for a in ans: print(a)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [list(input()) for _ in [0] * h]

x = []
y = []
for i in range(h):
    if "#" in a[i]:
        y += [i]
for i in range(w):
    t = []
    for j in range(h):
        t.append(a[j][i])
    if "#" in t:
        x += [i]

for i in y:
    for j in x:
        print(a[i][j], end="")
    print()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
graph = [list(input()) for _ in range(H)]
flg = True
while flg:
    loop = False
    for i in range(len(graph)):
        if "#" not in graph[i]:
            graph.pop(i)
            loop = True
            break
    if loop:
        continue
    for j in range(len(graph[0])):
        tate = [line[j] for line in graph]
        if "#" not in tate:
            for i in range(len(graph)):
                graph[i].pop(j)
            break
    else:
        flg = False
for line in graph:
    print("".join(line))

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]
A=[False]*H
B=[False]*W
for i in range(H):
  for j in range(W):
    if S[i][j]=='#':
      A[i]=True
      B[j]=True

for i in range(H):
  if A[i]:
    for j in range(W):
      if B[j]:
        print(S[i][j], end = '')
    print()

Submission status: Accepted

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

res = []
for i in range(h):
    line = input()
    if '#' in line:
        res.append(line)

ok_v_line = []
for i in range(w):
    v_line = [line[i] for line in res]
    if '#' in v_line:
        ok_v_line.append(i)

for line in res:
    final_line = [line[x] for x in ok_v_line]
    print(''.join(final_line))

Submission status: Accepted

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

for i in range(0, max(h, 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: Accepted

Solution code:
h, w = map(int, input().split())
l = []
for i in range(h):
    retu = list(input())
    if "#" in retu:
        l.append(retu)
ll = []
for i in zip(*l):
    if "#" in i:
        ll.append(i)
for i in zip(*ll):
    print("".join(i))