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:
import sys

h,w = map(int, sys.stdin.readline().split())

a = [input() for _ 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):
    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(input()) for i in range(h)]
A_np=np.array(A)
del_index=[]
del_row=[]
for i in range(h):
    if A[i].count('.')==len(A[i]):
        del_index.append(i)
for j in range(w):
    c=0
    for i in range(h):
        if A[i][j]=='#':
            c+=1
    if c==0:
        del_row.append(j)
del_index.sort(reverse=True)
del_row.sort(reverse=True)
for j in del_row:
    A_np=np.delete(A_np,j,1)
for i in del_index:
    A_np=np.delete(A_np,i,0)
ans=list(A_np)
if ans ==[]:
    print()
else:
    for i in range(len(ans)):
        print(*ans[i],sep='')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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:
#!/usr/bin/env python3
import numpy as np

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

    ok_i = []
    ok_j = []
    for i in range(H):
        for j in range(W):
            if a[i][j] == '#':
                ok_i.append(i)
                break

    for i in range(W):
        for j in range(H):
            if a[j][i] == '#':
                ok_j.append(i)
                break

    answer = []

    b = [aa for idx, aa in enumerate(a) if idx in ok_i]
    for i in range(len(b)):
        temp = []
        for j in range(W):
            if j in ok_j:
                temp.append(b[i][j])
        answer.append(temp)
    
    for i in range(len(answer)):

        print(''.join(answer[i]))





if __name__ == '__main__':
    main()

Submission status: Accepted

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

index = 0
row = []
while True:
    # 縦
    if hw[index][0] == '.':
        clearable = 0
        for i in range(W):
            if hw[index][i] == '.':
                clearable += 1
        if clearable != W:
            row.append(hw[index][:])
    else:
        row.append(hw[index][:])

    index += 1
    if index == H:
        break

# 転置して横と似たような処理で縦も処理する
rowt = [list(x) for x in list(zip(*row))]

index = 0
cols = []
while True:
    # 横
    if rowt[index][0] == '.':
        clearable = 0
        for i in range(len(rowt[index])):
            if rowt[index][i] == '.':
                clearable += 1
        if clearable != len(rowt[index]):
            cols.append(rowt[index][:])
    else:
        cols.append(rowt[index][:])

    index += 1
    if index == len(rowt):
        break

# 転置してるので元に戻す
ans = [list(x) for x in list(zip(*cols))]

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

Submission status: Accepted

Solution code:
def t(l_2d):
  return [list(i) for i in zip(*l_2d)]

def clean(a):
  a_white = ["."]*len(a[0])
  #print(a_white)
  a_ret=[]
  for ai in a:
    if ai!=a_white:
      a_ret.append(ai)
  return a_ret


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

a = clean(a)
#print(t(a))
a = t(clean(t(a)))

for ai in a:
  for aii in ai:
    print(aii, end="")
  print("")

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
A=[]
for i in range(H):
  a=list(input())
  if a != ["."]*W:
    A.append(a)
f = []
for i in range(W):
  flag=1
  for j in range(len(A)):
    if A[j][i]=="#":
      flag=0
      break
  if flag:
    f.append(i)
for i in range(len(A)):
  for j in range(W):
    if j not in f:
      print(A[i][j],end="")
  print()

Submission status: Accepted

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

A = []
for i in range(H):
    s = input()
    if '#' in s:
        A.append(list(s))

H = len(A)
B = []
for i in range(W):
    s = []
    for j in range(H):
        s.append(A[j][i])
    if "#" in s:
        B.append(s)

W = len(B)
for i in range(H):
    s = ""
    for j in range(W):
        s += B[j][i]
    print(s)

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
mat = []
for i in range(H):
    a = list(input())
    if '#' in a:
        mat.append(a)
answ = []
for i in range(W):
    flag = False
    for j in range(len(mat)):
        if mat[j][i] == '#':
            flag = True
    if flag:
        answ.append(i)
for i in range(len(mat)):
    ans = [mat[i][j] for j in answ]
    print(''.join(ans))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a=[list(input()) for i in range(h)]
b=[]
dl=[]
for i in a:
  if "#" in i:
    b.append(i)
for j in range(w):
  for i in range(len(b)):
    if b[i][j] == "#":
      break
    elif i == len(b)-1:
      dl.append(j)
dl.sort(reverse=True)
for i in dl:
  for j in range(len(b)):
    del b[j][i]
for c in b:
  print(*c,sep="")

Submission status: Accepted

Solution code:
import numpy as np

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

v_removed = raw[:, np.any(raw == '#', axis=0)]
vh_removed = v_removed[np.any(v_removed == '#', axis=1), :]

for s in vh_removed.tolist():
    print(''.join(s))

Submission status: Accepted

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


for i in range(H):
    temp = input()        
    if (temp.count("#") != 0):
        M.append(temp) 


H = len(M)


list_of_col = [] 

for i in range(W):
    t = ""
    for j in range(H):
        t += M[j][i]
    if (t.count("#") != 0):
        list_of_col.append(i)


for i in range(H):
    for j in range(W):
        if j in list_of_col:
            print(M[i][j],end="")
    print()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
ans = []
for _ in range(h):
    aw = input()
    if set(aw) != {'.'}:
        a.append(aw)

for i in zip(*a):
    if set(i) != {'.'}:
        ans.append("".join(list(i)))
        
for j in zip(*ans):
    print("".join(list(j)))

Submission status: Accepted

Solution code:
import numpy as np
h,w=map(int,input().split())
a=[input() for _ in range(h)]
a=np.asarray([list(s) for s in a if s!='.'*w]).T

h=len(a[0])
a=np.asarray([x for x in a if ''.join(x)!='.'*h]).T

for x in a:
  print(''.join(x))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[list(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 = [input() for i in range(h)]
l = [s for s in l if s.count("#") > 0]
check = [True] * w
for i in range(len(l[0])):
    check_row = True
    for j in range(len(l)):
        if l[j][i] == "#":
            check_row = False
    check[i] = check_row
ans = []
for i in range(len(l)):
    str_row = ""
    for j in range(len(l[0])):
        if not(check[j]):
            str_row += l[i][j]
    ans.append(str_row)
for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

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

#行の中で「....」があれば取り除く.
while "."*w in a:
    a.remove("."*w) #removeは該当要素のうち最初の要素を削除
    c += 1
    
#行と列の入れ替え
a = ["".join(column) for column in zip(*a)]
while "."*(h-c) in a:
    a.remove("."*(h-c))

#行と列を再度入れ替えて出力.
for row in zip(*a):
    print("".join(row))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
M=list(input() for _ in range(h))
c=[]
for i in range(h):
    if "#" not in M[i]:
        c.append(i)
for dot in c[::-1]:
    M.pop(dot)

c=[]
col=[]
for i in range(len(M[0])):
    flag=1
    for j in range(len(M)):
        if "#" in M[j][i]:flag=0
    if flag==1:c.append(i)

for i in c[::-1]:
    for row in M:
        list(row).pop(i)
for i in range(len(M)):
    flag=0
    for j in range(len(M[0])):
        if j not in c:
            print(*M[i][j],end="")
            flag=1
    if i<len(M)-1 and flag==1:print()

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
board = [input() for _ in range(h)]
skipi = set()
skipj = set()
for i in range(h):
  if not "#" in board[i]:
    skipi.add(i)
for j in range(w):
  cnt = 0
  for i in range(h):
    if board[i][j] == ".":
      cnt += 1
    if cnt == h:
      skipj.add(j)
for i in range(h):
  line = ""
  if i in skipi:
    continue
  for j in range(w):
    if j in skipj:
      continue
    line += board[i][j]
  print(line)

Submission status: Accepted

Solution code:
import numpy as np
if __name__ == '__main__':
    H, W = map(int, input().split())
    A = [None]*H
    row = [False]*H
    col = [False]*W
    for i in range(H):
        A[i] = str(input())
        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 = map(int, input().split())
a = [list(input()) for _ in range(h)]
a = [list(i) for i in zip(*a) if "#" in i]
a = [list(i) for i in zip(*a) if "#" in i]
for i in range(len(a)): print("".join(a[i]))

Submission status: Accepted

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

def del_rows(r):
  del list1[r]

def del_cols(c):
  for l in range(h):
    del list1[l][c]
i = 0
#colの削除
while True:
  flag = 1
  if i >= len(list1[0]):
    break
  for j in list1:
    if j[i] == "#":
      flag = 0
      break
  if flag:
    del_cols(i)
  else:
    i += 1
#rowの削除
i = 0
while True:
  if i >= len(list1):
    break
  if all(j == "." for j in list1[i]):
    del_rows(i)
  else:
    i += 1
for i in range(len(list1)):
  print("".join(list1[i]))

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[]
for i in range(h):
    li=str(input())
    if len(set(li))!=1:
        a.append(li)
    elif len(set(li))==1 and li[0]=="#":
        a.append(li)
      
cnt=[]
b=[]
for j in range(w):
    for k in range(len(a)):
        b.append(a[k][j])
    if len(set(b))==2: 
      cnt.append(j)
    elif len(set(b))==1:
      if b[0]=="#":
        cnt.append(j)       
    b=[]            
ans=""
for m in range(len(a)):
  for l in cnt:
    ans+=a[m][l]
  print(ans)
  ans=""

Submission status: Accepted

Solution code:
import numpy as np
H, W, *A = open(0).read().split()
H = int(H)
W = int(W)

A = list(map(lambda x: list(map(int, x.replace(".", "0").replace("#", "1"))), A))
A = np.array(A)
r = np.sum(A, axis = 0)
c = np.sum(A, axis = 1)

A = A[c != 0, :]
A = A[:, r != 0]

res = list(map(lambda x: "".join(list(map(str, list(x)))).replace("0", ".").replace("1", "#"), list(A)))
for x in res:
  print(x)

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
grid=[None]*H
skip_i=set()
skip_j=set()
for i in range(H):
  grid[i]=input()
  if grid[i].count(".")==W:
    skip_i.add(i)

for j in range(W):
  count=0
  for i in range(H):
    if grid[i][j]==".":
      count+=1
  if count==H:
    skip_j.add(j)
    
ans=["" for i in range(H-len(skip_i))]

for i in range(len(grid)):
  if i in skip_i:
    continue
  line=""
  for j in range(len(grid[i])):
    if j in skip_j:
      continue
    line+=(grid[i][j])
  print(line)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[list(input()) for i in range(h)]
#print(a)
H=[]
W=[]
for i in range(h):
    count=0
    for j in range(w):
        if a[i][j]==".":
            count+=1
    if count==w:
        H.append(i)
for i in range(w):
    count=0
    for j in range(h):
        if a[j][i]==".":
            count+=1
    if count==h:
        W.append(i)
for i in range(1,len(H)+1):
    for j in range(w):
        a[H[-1*i]][j]=""
for i in range(1,len(W)+1):
    for j in range(h):
        a[j][W[-1*i]]=""

for i in range(h):
    if not ("." in a[i] or "#" in a[i]):
        continue
    print("".join(a[i]))

Submission status: Accepted

Solution code:
f=lambda s:zip(*[t for t in s if'#'in t]);print(*map(''.join,f(f(open(0).readlines()))))

Submission status: Accepted

Solution code:
f=lambda s:zip(*[t for t in s if'#'in t])
print(*map(''.join,f(f(open(0).readlines()))))

Submission status: Accepted

Solution code:
H, W = map(int,input().split())
a = []
for i in range(H):
  a1 = input()
  if "#" in a1:
    a.append(a1)

b = []
for i in range(W):
  for j in range(len(a)):
    if a[j][i] == "#":
      break
  else:
      b.append(i)

for i in range(len(a)):
  ans = ""
  for j in range(W):
    if not j in b:
      ans += a[i][j]
  print(ans)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
grid = [list(input()) for _ in range(h)]
row_white = []
column_white = []
 
for i in range(h):
    for j in range(w):
        if grid[i][j] == '#':
            break
        if j == w - 1:
            row_white.append(i)
for i in range(len(row_white)):
    grid.pop(row_white[i] - i)
 
h = len(grid)
for j in range(w):
    for i in range(h):
        if grid[i][j] == '#':
            break
        if i == h - 1:
            column_white.append(j)
for j in range(len(column_white)):
    for i in range(h):
        del grid[i][column_white[j] - j]
for i in range(h):
    print(*grid[i], sep='')

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
grid = [list(input()) for _ in range(h)]
row_white = []
column_white = []

for i in range(h):
    for j in range(w):
        if grid[i][j] == '#':
            break
        if j == w - 1:
            row_white.append(i)
for i in range(len(row_white)):
    grid.pop(row_white[i] - i)

h = len(grid)
for j in range(w):
    for i in range(h):
        if grid[i][j] == '#':
            break
        if i == h - 1:
            column_white.append(j)
for j in range(len(column_white)):
    for i in range(h):
        del grid[i][column_white[j] - j]
for i in range(h):
    print(*grid[i], sep='')

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
masu = []
for i in range(h):
    tmp = list(str(input()))
    masu.append(tmp)
count = 0
for i in range(len(masu)):
    if '#' not in masu[i - count]:
        del masu[i - count]
        count += 1

count = 0
x = int(len(masu[0]))
for i in range(x):
    tmp = []
    for j in range(len(masu)):
        tmp.append(masu[j][i - count])
    if '#' not in tmp:
        for k in range(len(masu)):
            del masu[k][i - count]
        count += 1

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

Submission status: Accepted

Solution code:
BLACK = '#'
H, W = map(int, input().split())
a = [list(input()) for _ in range(H)]
a = [x for x in a if x.count(BLACK) != 0]
H = len(a)
idx = []
for j in range(W):
    if [a[i][j] for i in range(H)].count(BLACK) == 0:
        idx.append(j)
a = [[x for j, x in enumerate(a[i]) if j not in idx] for i in range(H)]
for i in range(H):
    print(''.join(a[i]))

Submission status: Accepted

Solution code:
h, w = list(map(int, input().split()))
grid = []
for i in range(h):
    temp = list(input())
    if "#" in temp:
        grid.append(temp)
    else:
        h -= 1
i = 0
while i < len(grid[0]):
    for j in range(h):
        if grid[j][i] == "#":
            i += 1
            break
        if j == h - 1:
            for k in range(h):
                del grid[k][i]
for i in range(h):
    print("".join(grid[i]))

Submission status: Accepted

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

cut_h = [i for i in range(h)]
cut_w = [j for j in range(w)]
for i in range(h):
  for j in range(w):
    if list_c[i][j] == "#":
      if i in cut_h:
        cut_h.remove(i)
      if j in cut_w:
        cut_w.remove(j)

for i in range(h):
  if i not in cut_h:
    temp = ""
    for j in range(w):
      if j not in cut_w:
        temp += list_c[i][j]
    print(temp)

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
area = []
for _ in range(H):
  s = input()
  area.append(list(s))

counterh = []
area = [area[i] for i in range(len(area)) if area[i].count('.')!=len(area[i])]

counterw = [1 for i in range(len(area[0]))]
for j in range(len(area)):
  for k in range(len(area[0])):
    if area[j][k] == '#':
      counterw[k] *= 0
Answer = []
for item in area:
  item = [item[i] for i in range(len(item)) if counterw[i] == 0]
  Answer.append(item)    

for o in range(len(Answer)):
  print(''.join(Answer[o]))

Submission status: Accepted

Solution code:
#テストファイルで実行する時
import sys
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')

#2次元的な入れ方
h,w = map(int,input().split())
l = []
for i in range(h):
	x = list(input())
	#読み込む文字列xの中に#がある場合
	if '#' in x:
		l.append(x)
	else:
		h = h - 1

test = 0

for i in range(w):
	test = 0
	for j in range(h):
		if l[j][i] == '.':
			test = test + 1
	#print(test)
	if test == h :
		for k in range(h):
			l[k][i] = ''

for i in range(h):
	print(''.join(l[i]))

Submission status: Accepted

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

L=[]
for i in range(h):
  a=list(input())
  if "#" in a:
    L.append(a)
import numpy as np
A=[]
tenti=np.array(L).T
for i in range(w):
  if "#" in tenti[i]:
    A.append(tenti[i])
tenti=np.array(A).T 
ans=""

for i in range(len(tenti)):
  for j in range(len(tenti[i])):
    ans+=tenti[i][j]
  print(ans)
  ans=""

Submission status: Accepted

Solution code:
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )
# from itertools import accumulate
# from collections import deque

from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

import random


def main():
    h,w = map(int, input().strip().split())
    g = [input().strip() for _ in range(h)]
    gg  = [col for col in zip(*g) if("#" in col)]
    
    eprint("gg ",end=": \n")
    eprint(gg)
    for elem in gg:
        eprint(elem)
        
    gg = [row for row in zip(*gg) if("#" in row)]
    eprint("gg ",end=": \n")
    eprint(gg)
    # for elem in gg:
    #     eprint(elem)
    
    for S in gg:
        print("".join(S))
    return

if __name__ == '__main__':
    main()


# trA  = [list(col) for col in zip(*A)]

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
grid = []
count_array = [0] * W
for _ in range(H):
    S = input()
    if '#' in S:
        grid.append(S)
        for i in range(W):
            if S[i] == '.':
                count_array[i] += 1
delete_target = []
for i in range(W):
    if count_array[i] == len(grid):
        delete_target.append(i)
ans = []
for i in grid:
    tmp = ''
    for k in range(W):
        if k in delete_target:
            continue
        tmp += i[k]
    ans.append(tmp)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

def reduce(p, q):
    common = fractions.gcd(p, q)
    return (p//common , q//common )
# from itertools import accumulate
# from collections import deque

import random


def main():
    H,W = map(int, input().strip().split()) # H行 W列
    G=[]
    for i_row in range(H):
        G.append(input().strip())
    eprint("graph G:")
    eprint(G)

    l_flag_row_all_dot_flag=[ 1 for _ in range(H) ]
    for i_row in range(H):
        for j_col in range(W):
            if G[i_row][j_col]!=".":
                l_flag_row_all_dot_flag[i_row]=0


    l_flag_col_all_dot_flag=[ 1 for _ in range(W) ]
    for j_col in range(W):
        for i_row in range(H):
            if G[i_row][j_col]!=".":
                l_flag_col_all_dot_flag[j_col]=0

    for i_row in range(H):
        if l_flag_row_all_dot_flag[i_row]==1:
            continue
        for j_col in range(W):
            if l_flag_col_all_dot_flag[j_col]==1:
                continue
            print(G[i_row][j_col],end="")
        print()






    # for i_row in range(H):      # H is length of row
    #     if G[i_row] == str(["."* W ]):
    #         G.pop(i_row)

    # all_dot_flag=1
    # for j_col in range(W):      # W は列の長さ
    #     for i_row in range(H):  # H は行の長さ
    #         G[i_row][j_col] != "."
    #         failure_flag=0
    #     if all_dot_flag==1:
    #         for ii in range(H):
    #             G.pop()
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

r = set()
c = set()

for i in range(h):
    for j in range(w):
        if p[i][j] == '#':
            r.add(i)
            c.add(j)

for i in range(h):
    for j in range(w):
        if i in r and j in c:
            print(p[i][j], end='')
    if i in r:
        print()

Submission status: Accepted

Solution code:
import numpy as np

HW=list(map(int,input().split()))
H=HW[0]
W=HW[1]
a = [input().split() for l in range(H)]

for h in range(H):
    a[h] = [i for i in a[h] if i != '.'*W]

a=list(filter(None, a))
b=[]
for column in range(W):
    tmp=''
    for row in range(len(a)):
        tmp+=a[row][0][column:column+1]
    if tmp=='.'*len(a):
        b.append(column)

tmp2=[]
dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]
for j in range(len(a)):
    tmp2.append(list(a[j][0]))
  
for t in range(len(tmp2)):
    tmp2[t]=dellist(tmp2[t],b)
    tmp2[t]=''.join(tmp2[t])
print('\n'.join(tmp2))

Submission status: Accepted

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

for aa in A:
    flag = 0
    for a in aa:
        if a == "#":
            flag = 1
            break
    if flag:
        B.append(aa)

for i in range(w):
    flag = 1
    for j in range(len(B)):
        if B[j][i] == "#":
            flag = 0
            break
    if flag:
        for j in range(len(B)):
            B[j][i] = ""

[print("".join(b)) for b in B]

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=list(map(int,input().split(" ")))
A=np.full((H,W),".",np.str)

# 入力を格納
for h in range(H):
    A[h,:]=list(input())

# 各行について
for h in reversed(range(H)):
    if (A[h,:]==".").all()==True: # 全ての要素が"."の場合行を削除
        A=np.delete(A,h,axis=0)

# 各列について
for w in reversed(range(A.shape[1])):
    if (A[:,w]==".").all()==True: # 全ての要素が"."の場合列を削除
        A=np.delete(A,w,axis=1)

# 出力
for a in A:
    print("".join(a))

Submission status: Accepted

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

skipRow = set()
skipCol = set()

for h, line in enumerate(A):
    if '#' not in set(line):
        skipRow.add(h)
for w in range(W):
    if all(A[h][w] == '.' for h in range(H)):
        skipCol.add(w)

for i in range(H):
    if i in skipRow:
        continue
    line = [a for w, a in enumerate(A[i]) if w not in skipCol]
    print(''.join(line))

Submission status: Accepted

Solution code:
H,W=[int(s) for s in input().split()]
s=''
for i in range(W):
  s = s + '.' 
ls=[]
for i in range(H):
  x=input()
  if x!=s:
    ls.append(list(x))
i=0
for j in range(W):
  for e in ls:
    if e[i]=='#':
      i+=1
      break
  else:
    for e in ls:
      e.pop(i)
for e in ls:
  print(''.join(e))

Submission status: Accepted

Solution code:
H , W = map(int,input().split())
matrix = [list(input()) for _ in range(H)]
delete_column = []
delete_row = []
ans = []
for row in range(H):
    if not "#" in matrix[row]:
        delete_row.append(row)
for column in range(W):
    columnFlag = True
    for row in range(H):
        if matrix[row][column] == "#":
            columnFlag = False
            break
    if columnFlag:
        delete_column.append(column)
for row in range(H):
    tmp_list = []
    for column in range(W):
        if row in delete_row or column in delete_column:
            continue
        tmp_list.append(matrix[row][column])
    if not tmp_list == []:
        ans.append(tmp_list)
for a in ans:
    print("".join(a))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
grid = []
for i in range(H):
    a = input()
    l = []
    for i in a:
        l.append(i)
    grid.append(l)
grid_1 = []
delete = []
for i,job in enumerate(grid):
    count = 0
    for j in job:
        if(j == "."):
            count += 1
    if(count != W):
        grid_1.append(job)
count = 0
for i in delete:
    grid.pop(i-count)
    count += 1
grid_3 = []
for Row in zip(*grid_1):
    w = len(Row)
    count = 0
    for j in Row:
        if(j == "."):
            count += 1
    if(count != w):
        grid_3.append(Row)
for Row in zip(*grid_3):
    ans = ""
    for j in Row:
        ans += j
    print(ans)

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
a = []
for h in range(H):
    row = list(input())
    if '#' in row:
        a.append(row)
H = len(a)
for w in range(W):
    T = 1
    for h in range(H):
        if a[h][w] == '#':
            T = 0
            break
    if T == 1:
        for h in range(H):
            a[h][w] = 0
for h in range(H):
    a[h] = [w for w in a[h] if w != 0]
for h in range(H):
    print(''.join(a[h]))

Submission status: Accepted

Solution code:
import numpy as np
H,W = map(int,input().split())
a = np.array([list(input()) for _ in range(H)])
dlisx = np.any(a == "#",axis = 0)
dlisy = np.any(a == "#",axis = 1)
dlx = []
dly = []
for i,x in enumerate(dlisx):
    if not x:
        dlx.append(i)
for i,y in enumerate(dlisy):
    if not y:
        dly.append(i)

ans = np.delete(np.delete(a,dlx,1),dly,0)
for a in ans:
    print("".join(a))

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

H,W = map(int,input().split(' '))
l = [list(input()) for _ in range(H)]

white_row = [True]*H
white_col_dp = []
for i in range(H):
    for j in range(W):
        elm = l[i][j]
        if elm=='#':
            white_row[i] = False
            white_col_dp.append(j)
ANS = []
white_col_dp = set(white_col_dp)
for i in range(H):
    if not white_row[i]:
        tmp = []
        for j in range(W):
            if j in white_col_dp:
                tmp.append(l[i][j])
        ANS.append(''.join(tmp))

for i in ANS:
    print(i)

Submission status: Accepted

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

for i in A:
    if '#' in i:
        for i,v in enumerate(i):
            if not blank[i]:
                print(v,end='')
        print()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[]
b=[]
f=0
for i in range(h):
  b=input()
  if b!='.'*w:
    a.append(b)
ans=['' for j in range(len(a))]
for i in range(len(a[0])):
  f=0
  for j in range(len(a)):
    if a[j][i]=='#':
      f=1
      break
  if f==1:
    for k in range(len(a)):
      ans[k]+=a[k][i]
for i in range(len(a)):
  print(ans[i])

Submission status: Accepted

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

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

h_blank = [False]*h
w_blank = [False]*w
for i in range(h):
  blank = True
  for j in range(w):
    if a[i][j] == '#':
      blank = False
      break
  if blank:
    h_blank[i] = True

for i in range(w):
  blank = True
  for j in range(h):
    if a[j][i] == '#':
      blank = False
      break
  if blank:
    w_blank[i] = True

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