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:
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):
    if row[i] == True:
        for j in range(w):
            if col[j] == True:
                print(a[i][j],end = '')
        print()

Submission status: Accepted

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

for i in range(H):
    sharp_cnt = a[i].count("#")
    if sharp_cnt != 0:
        ans1.append(a[i])

slicer = []
for j in range(W):
    sharp_cnt = 0
    for i in range(len(ans1)):
        if ans1[i][j] == "#":
            sharp_cnt +=1
    if sharp_cnt == 0:
        slicer.append(j)

del_cnt = 0
for i in slicer:
    i = i - del_cnt
    for j in ans1:
        del j[i]
    del_cnt += 1

for i in ans1:
    print(*i, sep = "")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
ans_index = []

def get_index(s):
    a = ""
    for ans in ans_index:
        a += s[ans]
    return a

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        s = input()
        if s != "." * W:
            A.append(s)

    for w in range(W):
        add = True
        for h in range(len(A)):
            if A[h][w] != ".":
                add = False
                break
        if not add:
            ans_index.append(w)

    #print(A, ans_index)

    for line in map(get_index, A):
        print("".join(line))
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

tate,yoko = set(),set()
for i in range(H):
    t = True
    for j in range(W):
        if a[i][j] == "#":
            t = False
            break
    if t:
        tate.add(i)
for j in range(W):
    y = True
    for i in range(H):
        if a[i][j] == "#":
            y = False
            break
    if y:
        yoko.add(j)

ct = 0
for t in tate:
    a = a[:t-ct] + a[t+1-ct:]
    ct += 1

cy = 0
for y in yoko:
    for i in range(H-len(tate)):
        a[i] = a[i][:y-cy] + a[i][y+1-cy:]
    cy += 1

for i in range(H-len(tate)):
    print("".join(a[i]))

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline

def main():
    H, W = map(int, readline().split())
    grid = []
    for _ in range(H):
        A = list(readline()[:-1])
        if '#' in A:
            grid.append(A)

    for i in range(W-1, -1, -1):
        flag = True
        for j in range(len(grid)):
            if grid[j][i] == '#':
                flag = False
                break
        if flag:
            for k in range(len(grid)):
                del grid[k][i]
    
    for k in range(len(grid)):
        print(''.join(grid[k]))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

for s in S:
    if '#' not in s:
        continue
    T.append(s)

S = []
for t in list(zip(*T)):
    if '#' not in t:
        continue
    S.append(t)
    
for s in list(zip(*S)):
    print(''.join(map(str, s)))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
for i in range(h):
    s = input()
    if s.count('.') != w:
        a.append(s)
b = []
for i in range(w):
    f = True
    for x in a:
        if x[i] != '.':
            f = False
    if f:
        b.append(i)
for x in a:
    for i in range(len(x)):
        f = True
        for j in b:
            if i == j:
                f = False
        if f:
            print(x[i], end='')
    print()

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
A = [list(input()) for _ in range(H)]
for h in range(H):
  if A[h].count('.') == W:
    for w in range(W):
      A[h][w] = ''
for h in range(H):
  for w in range(W):
    if A[h][w] == '.':
      for i in range(H):
        if A[i][w] == '#':
          break
        if i == H-1:
          for j in range(H):
            A[j][w] = ''

for i in range(H):
  if ''.join(A[i]) == '':
    continue
  print(''.join(A[i]))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [input() for i in range(h)]
col = [0]*h
row = [0]*w
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            col[i] = 1
            row[j] = 1
for i in range(h):
    ans=""
    for j in range(w):
        if col[i] == 1 and row[j] == 1:
            ans+=a[i][j]
    if ans!="":
        print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


def read():
    H, W = map(int, input().strip().split())
    A = []
    for i in range(H):
        a = list(input().strip())
        A.append(a)
    return H, W, A


def solve(H, W, A):
    is_skip_rows = [True for i in range(H)]
    is_skip_cols = [True for j in range(W)]
    for i in range(H):
        for j in range(W):
            if A[i][j] == '#':
                is_skip_rows[i] = False
                is_skip_cols[j] = False
    for i in range(H):
        if is_skip_rows[i]:
            continue
        line = []
        for j in range(W):
            if is_skip_cols[j]:
                continue
            line.append(A[i][j])
        print(''.join(line))


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

Solution code:
import numpy as np
h,w = map(int,input().split())
s = []
for i in range(h):
    tmp = list(input())
    if len(set(tmp)) == 1 and tmp[0] == '.':
        continue
    s.append(tmp)
ss = np.array(s).T
ans1 = []
si = ss.tolist()

for i, w in enumerate(si):
    if len(set(w)) == 1 and w[0] == '.':
        continue
    else:
        ans1.append(w)
ans = np.array(ans1).T.tolist()

for i, w in enumerate(ans):
    print(''.join(w))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
a = [[i == "#" for i in list(input())] for _ in range(h)]
line,row = [0]*w,[0]*h
for i in range(h):
  for j in range(w):
    if a[i][j]:
      line[j] = 1
      row[i] = 1
for i in range(h):
  if not row[i]:
    continue
  ans = ""
  for j in range(w):
    if line[j]:
      ans += "#"*a[i][j]+"."*(not a[i][j])
  print(ans)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
s=[]
for i in range(h):
  t=input()
  if t.count('.')!=len(t):
    s.append(t)

l=[list(x) for x in zip(*s)]
t2=[]
for e in l:
  if e.count('.')!=len(e):
    t2.append(e)

ans=[list(x) for x in zip(*t2)]
for e in ans:
  print(''.join(e))

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
A = []
for i in range(h):
    s = input()
    #print('---', s)
    if not s == '.'*w:
        A.append([j for j in s])
if len(A) > 1:
    for j in range(len(A[0])-1,-1,-1):
        
        c = 0
        for i in range(len(A)-1,-1,-1):
            #print(i,j)
            if A[i][j] == '.':
                #print(A[i])
                c +=1
        if c == len(A):
            for k in range(len(A)-1,-1,-1):
                A[k].pop(j)
else:
    for l in range(len(A[0])-1,-1,-1):

        if A[0][l] == '.':
            A[0].pop(l)

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

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
grid = []
for _ in range(H):
    a = [i for i in input()]
    if "#" in a:
        grid.append(a)
grid = np.array(grid)
grid_T = grid.T
ans = []
for i in range(W):
    if "#" in grid_T[i]:
        ans.append(grid_T[i])
ans = np.array(ans).T
for i in range(ans.shape[0]):
    print("".join(ans[i]))

Submission status: Accepted

Solution code:
import numpy as np

def ABC107B(h, w, a):
    b = np.zeros((h, w), dtype=str)
    for i in range(h):
        b[i, :] = np.array(list(a[i]))
    H = []
    W = []
    for i in range(h):
        if any(b[i, :] == '#'):
            H.append(i)
    for j in range(w):
        if any(b[:, j] == '#'):
            W.append(j)
    lenH = len(H)
    lenW = len(W)
    for i in range(h):
        if H.count(i) == 1:
            string = ''
            for j in range(w):
                if W.count(j) == 1:
                    string = string + b[i, j]
            print(string)

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

Submission status: Accepted

Solution code:
import numpy as np
h,w=map(int,input().split())
a=np.array([ list(input()) for i in range(h)])
count=0
d_w=[]
d_h=[]
for i in range(0,h):
  count=0
  for j in range(0,w):
    if a[i][j]==".":
      count+=1
  if count==w:
    d_w.append(i)
for i in range(0,w):
  count=0
  for j in range(0,h):
    if a[j][i]==".":
      count+=1
  if count==h:
    d_h.append(i)
a=np.delete(a,d_w,0)
a=np.delete(a,d_h,1)
for i in a:
  print("".join(i))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
mat = []
idx = []
mat2 = []
for i in range(h):
    tmp = input()
    if tmp.count('.') != w:
        mat.append(tmp)

###行と列を入れ替える
for i in range(w):
    tmp2 = ''
    for j in range(len(mat)):
        tmp2 += mat[j][i]
    mat2.append(tmp2)

mat.clear()
for i in range(len(mat2)):
    if mat2[i].count('.') != len(mat2[i]):
        mat.append(mat2[i])

for i in range(len(mat[0])):
    ans = ''
    for j in range(len(mat)):
        ans += mat[j][i]
    
    print(ans)

Submission status: Accepted

Solution code:
import numpy as np
def main():
    H,W = map(int,input().split())
    grid = np.array([list(input()) for _ in range(H)],str)
    grid = grid[:,np.any(grid == '#',axis = 0)]
    grid = grid[np.any(grid == '#',axis = 1),:]
    print('\n'.join(''.join(row) for row in grid))
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7

h,w=MI()
data=[list(input().rstrip()) for i in range(h)]
#print(data)
deletes=[]
for i in range(h):
    count=0
    for j in range(w):
        if data[i][j]==".":
            count+=1
    if count==w:
        deletes.append(i)
for j in list(reversed(deletes)):
    del data[j]
#print(data)
h-=len(deletes)
data2=[[0 for i in range(h)] for j in range(w) ]
for i in range(w):
    for j in range(h):
        data2[i][j]=data[j][i]
#print(data2)
deletes2=[]
for i in range(w):
    count=0
    for j in range(h):
        if data2[i][j]==".":
            count+=1
    if count==h:
        deletes2.append(i)
for j in list(reversed(deletes2)):
    del data2[j]
w-=len(deletes2)
#print(data2)
data3=[[0 for i in range(w)] for j in range(h)]
#print(h,w)
#print(data3)
for i in range(h):
    for j in range(w):
        data3[i][j]=data2[j][i]
#print(data3)
for i in range(h):
    for j in range(w):
        print(data3[i][j],end="")
    print("")

Submission status: Accepted

Solution code:
MOD = 10 **9 + 7
INF = 10 ** 10
def main():
    H,W = map(int,input().split())
    grid = [list(input()) for _ in range(H)]
    for i in range(H - 1,-1,-1):
        flag = True
        for j in range(W):
            if grid[i][j] == '#':
                flag = False
                break
        if flag:
            grid = grid[:i] + grid[i + 1:]
            H -= 1

    for i in range(W - 1,-1,-1):
        flag = True
        for j in range(H):
            if grid[j][i] == '#':
                flag = False
                break
        if flag:
            for j in range(H):
                grid[j] = grid[j][:i] + grid[j][i + 1:]
    for i in range(H):
        print(''.join(grid[i]))
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
for i in range(h):
    ai = [j for j in input()]
    if set(ai) == {'.'}:
        continue
    a.append(ai)
len_a = len(a)
at = list(zip(*a))
at2 = []
for ati in at:
    if set(ati) != {'.'}:
        at2.append(ati)
att = list(zip(*at2))
for ai in att:
    print(*ai, sep='')

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
lis=[]
for i in range(h):
  lis.append(input())
tate=[]
yoko=[]
for i in range(0,w):
  for j in range(0,h):
    if lis[j][i]=="#":
      tate.append(i)
      break

for i in range(0,h):
  for j in range(0,w):
    if lis[i][j]=="#":
      yoko.append(i)
      break

for x in yoko:
  for y in tate:
    if y != tate[len(tate)-1]:
      print(lis[x][y],end="")
    else:
      print(lis[x][y])

Submission status: Accepted

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

b = []

for i in a:
    if i != '.' * W:
        b.append(i)

h = len(b)

ans = [[] for _ in range(h)]
        
for i in range(W):
    jdg = True
    for j in range(h):
        if b[j][i] != '.':jdg = False
        ans[j].append(b[j][i])
    if jdg:
        for j in range(h):
            ans[j].pop()

for a in ans:
    print(*a, sep='')

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
A=[input() for i in range(h)]
B=[]
for i in range(h):
    if '#' in A[i]:
        B.append(A[i])
def rot(X):
    C=[]
    for l in range(len(X[0])):
        C_row=[]
        for m in X:
            C_row.append(m[l])
        C.append(C_row)
    return C
D=rot(B)
E=[]
for i in range(w):
    if '#' in D[i]:
        E.append(D[i])
F=rot(E)
for f in F:
    print(''.join(f))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
grid = []
ignore_i = []
ignore_j = []
for i in range(h):
    l = list(input())
    grid.append(l)
    
    if  not("#" in l):
        ignore_i.append(i)

for j in range(w):
    white = True
    for i in range(h): 
        if grid[i][j] == "#":
            white = False
            break
    if white:
        ignore_j.append(j)

# print(ignore_i)
# print(ignore_j)

for i in range(h):
    if i in ignore_i:
        continue

    for j in range(w):
        if j in ignore_j:
            continue
        print(grid[i][j], end="")
    print("\n")

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[[1 if s=='#' else 0 for s in input()] for i in range(h)]
H=[]
W=[]
at=list(map(list,zip(*a)))
for i in range(h):
    if sum(a[i])==0:
        H.append(i)
for i in range(w):
    if sum(at[i])==0:
        W.append(i)
ans=[]
for i in range(h):
    if i not in H:
        ans.append([])
        for j in range(w):
            if j not in W:
                if a[i][j]==1:
                    ans[-1].append('#')
                else:
                    ans[-1].append('.')
for i in range(len(ans)):
    print(''.join(ans[i]))

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    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()



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#他の方のきれいなACのから勉強させてもらいました

h,w=map(int, input().split())
a1=[list(input()) for _ in range(h)]
# print(a1)
a2=[b for b in a1 if b.count('#')]
# print(a2)
a3=[b for b in list(zip(*a2)) if b.count('#')]
# print(a3)
ans=list(zip(*a3))
# print(ans)
for i in ans:
    print(''.join(i))

Submission status: Accepted

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

A = []

for i in range(H):
  S = input()
  if S != "."*W:
    A.append(S)

Wcount = [0]*W

for i in range(len(A)):
  for j in range(W):
    if A[i][j] == "#":
      Wcount[j] = 1

      
for i in range(len(A)):
  S = ""
  for j in range(W):
    
    if Wcount[j] == 1:
      S = S + str(A[i][j])
    
  print(S)

Submission status: Accepted

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

area = []
for i in range(h):
    tmp = str(input())
    if tmp.find('#') == -1:
        #print('Not find')
        continue
    else:
        area.append(tmp)

#print(area)

area = list(zip(*area))

#print(area)

ans_list = []
for tmp in area:
    tmp = list(tmp)
    #print(tmp)
    if ('#' in tmp) == False:
        #print('Not find')
        continue
    else:
        ans_list.append(tmp)

ans_list = list(zip(*ans_list))

#print(ans_list)

for tmp in ans_list:
    ans = ''    
    for j in tmp:
        ans += j
    print(ans)

Submission status: Accepted

Solution code:
#ABC107-B
h,w = map(int,input().split())
grid = [input() for _ in range(h)]

row = [False for _ in range(h)]
col = [False for _ in range(w)]

for i in range(h):
    for j in range(w):
        if grid[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(grid[i][j],end='')
                
        print()

Submission status: Accepted

Solution code:
# coding: utf-8
import re
import math
from collections import defaultdict
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
def hani(x,min_,max_):
    ret=x
    if x<min_:ret=min_
    if x>max_:ret=max_
    return ret
def seifu(x):
    return x//abs(x)

###################################################
def main():
    H,W=map(int,input().split())
    A=[input() for a in range(H)]
    dh=[]
    dw=[]
    for a in range(len(A)):
        if A[a]=="."*W:
            dh.append(a)
    for a in range(W):
        s=""
        for b in range(H):
            s+=A[b][a]
        if s=="."*H:
            dw.append(a)
    ans=[]
    for a in range(H):
        if a not in dh:
            ans.append("")
        else:
            continue
        for b in range(W):
            if b not in dw:
                ans[-1]+=A[a][b]
    for a in ans:
        print(a)

        
main()

Submission status: Accepted

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

board = list()
line = list()

for x in range(0, H):
    word = input()
    for y in word:
        line.append(y)
    if '#' in line:
        board.append(line)
    line = list()

H = len(board)

goodx = [True]*W

judge = True

for a in range(0, W):
    for b in range(0, H):
        if board[b][a] == '#':
            judge = False
    if judge:
        goodx[a] = False
    judge = True

for a in range(0, H):
    for b in range(0, W):
        if goodx[b]:
            print(board[a][b], end='')
    print('')

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
A=[]
for i in range(h):
    a=list(input())
    if "#" in a:
        A.append(a)
    else:
        h-=1

num=[]
for i in range(w):
    for j in range(h):
        if A[j][i]=="#":
            num.append(i)
            break
for i in range(h):
    for j in num:
        print(A[i][j],end="")
    print()

Submission status: Accepted

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

row = []
clm = []
for i in range(H):
    if '#' not in set(s[i]):
        row.append(i)
for i in range(W):
    if '#' not in set([v[i] for v in s]):
        clm.append(i)

for i in range(H):
    if i in row:
        continue
    ans = ''
    for j in range(W):
        ans += '' if j in clm else s[i][j]
    print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
h, w = map(int, input().split())
a = [[j for j in input()] for i in range(h)]
# print(a)
x = []
y = []
for i in range(h):
    if a[i] == ["." for j in range(w)]:
        x.append(i)
for i in range(w):
    flag = True
    for j in range(h):
        if a[j][i] == "#":
            flag = False
            break
    if flag:
        y.append(i)
# print("x =", x)
# print("y =", y)
for i in range(h):
    flag = False
    for j in range(w):
        if i not in x and j not in y:
            flag = True
            print(a[i][j], end="")
    if flag:
        print()

Submission status: Accepted

Solution code:
import sys
from collections import deque, Counter, defaultdict
from itertools import accumulate  # 累積和
from bisect import bisect_left, bisect
from heapq import heappop, heappush  # 優先度付きキュー
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy

h, w = map(int, input().split())
rows = []
not_skip = defaultdict(bool)
for i in range(h):
    row = input()
    if "#" in row:
        rows.append(row)
        for i in range(w):
            if row[i] == "#":
                not_skip[i] = True

for row in rows:
    for i in range(w):
        if not_skip[i]:
            print(row[i], end="")
    print()

Submission status: Accepted

Solution code:
def rotate(mat):
  mat2 = []
  for i in range(len(mat[0])):
    s = ""
    for k in range(len(mat)):
      s = s + mat[k][i]
    mat2.append(s)
  return mat2

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

for count in range(H+W):
  for i in range(len(mat)-1, -1, -1):
    if not "#" in mat[i]:
      del mat[i]
  mat = rotate(mat)
  for i in range(len(mat)-1, -1, -1):
    if not "#" in mat[i]:
      del mat[i]
  mat = rotate(mat)
  
for i in range(len(mat)):
  print(mat[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)])
del_i = []
for i in range(H):
    if all(A[i, :] == '.'):
        del_i.append(i)
del_j = []
for j in range(W):
    if all(A[:, j] == '.'):
        del_j.append(j)
A = np.delete(A, del_i, 0)
A = np.delete(A, del_j, 1)
for i in range(A.shape[0]):
    print(''.join(A[i]))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
S = []
for _ in range(H):
  a = list(input())
  if a.count('.') < W: S.append(a)
S_t = list(map(list, zip(*S)))
S_re = []
for i in range(W):
  if S_t[i].count('.') < len(S): S_re.append(S_t[i])

S_tt = list(map(list, zip(*S_re)))
for i in S_tt:
  print(''.join(i))

Submission status: Accepted

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


def main():
    H, W = [int(x) for x in input().split()]
    a = [input() for _ in range(H)]
    a = [ai for ai in a if "#" in ai]
    ar = zip(*[bi for bi in zip(*a) if "#" in bi])
    for ai in ar:
        print("".join(ai))


if __name__ == '__main__':
    main()