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 numpy as np
 
h,w = map(int,input().split())
a = [list(input()) for i in range(h)]

arr=[]
arr2=[]
for i in a:
  if '#' in i:
    arr.append(i)
    
ar = np.array(arr)
arT = ar.T
 
for i in arT:
  if '#' in i:
    arr2.append(i)
    
arr3 = np.array(arr2)
arr4 = arr3.T
 
arr5=arr4.tolist()

for i in range(len(arr5)):
    print("".join(arr5[i]))

Submission status: Accepted

Solution code:

h,w=map(int,input().split())
List=[]
List_gyou=[""]*w
ans=[]
kotae=[]

for i in range(h):
    a=input()
    check=set(a)
    if (check!={"."}):
        List.append(a)
        for j in range(w):
            List_gyou[j]+=a[j]
            
for i in range(w):
    check=set(List_gyou[i])
    if (check!={"."}):
        ans.append(List_gyou[i])

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

#print(List)
#print(List_gyou)

Submission status: Accepted

Solution code:
import numpy as np

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

for i in a:
  if '#' in i:
    ans1.append(i)
    
gyouretu = np.array(ans1)
gyouretuT = gyouretu.T

for i in gyouretuT:
  if '#' in i:
    ans2.append(i)
    
ans = np.array(ans2)
answer = ans.T

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

Submission status: Accepted

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

for i in range(h):
    if all(c == "." for c in g[i]):
        for j in range(w):
            flg[i][j] = 1

for j in range(w):
    if all(d[j] == "." for d in g):
        for i in range(h):
            flg[i][j] = 1

res = []
for i in range(h):
    su = ""
    for j in range(w):
        if not flg[i][j]:
            su += g[i][j]
    if su:
        res.append(su)
print(*res, sep="\n")

Submission status: Accepted

Solution code:
h,w = map(int, input().split())
a = [list(input()) for _ in range(h)]
now = 0
while True:
    if ("#" in a[now]):
        now += 1
    else:
        a.pop(now)
    if (now >= len(a)):
        break
#print(a)
ans = [[] for _ in range(len(a))]
for i in range(w):
    f = 0
    for j in range(len(a)):
        if (a[j][i]=="#"):
            f += 1
    if (f>0):
        for j in range(len(a)):
            ans[j].append(a[j][i])
for i in range(len(a)):
    print(''.join(ans[i]))

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
#sys.stdin = open("input.txt", "r")
#sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)



n,m=l()
A=[input() for i in range(n)]
r=set()
c=set()
for i in range(n):
    if "#" in A[i]:
        r.add(i)

for i in range(m):
    x=[A[j][i] for j in range(n)]
    if "#" in x:
        c.add(i)
for i in range(n):
    if(i not in r):
        continue
    for j in range(m):
        if(j in c):
            print(A[i][j],end="")
    print()

Submission status: Accepted

Solution code:
# import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

res = []
for h in aHW:
    if '#' in h:
        res.append(h)

res = list(zip(*res))
res2 = []
for h in res:
    if '#' in h:
        res2.append(h)

res2 = list(zip(*res2))

for h in res2:
    print(''.join(h))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = [input() for _ in range(H)]
count = 0
while True:
  length = len(a)
  a = [i for i in a if not(len(set(i)) == 1 and i[0] == '.')]
  if len(a) == length:
    break
  a = list(zip(*a))
  count += 1
if count % 2 != 0: a = list(zip(*a))
[print(''.join(i)) for i in list(a)]

Submission status: Accepted

Solution code:
import numpy as np

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


def compress_row(table):
    new_table = []
    compressed = False
    for row in table:
        if all([c == '.' for c in row]):
            compressed = True
            continue
        else:
            new_table.append(row)

    return compressed, np.array(new_table)


def compress_col(table):
    tr_table = table.T
    compressed, new_tr_table = compress_row(tr_table)
    return compressed, new_tr_table.T


while True:
    row_compressed, table = compress_row(table)
    col_compressed, table = compress_col(table)

    if (not row_compressed) and (not col_compressed):
        break

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

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
field = [input() for _ in range(H)]
comp_rows = []
comp_cols = []
for i in range(H):
    if field[i] == "." * W:
        comp_rows.append(i)
for j in range(W):
    if "".join(field[i][j] for i in range(H)) == "." * H:
        comp_cols.append(j)
for i in range(H):
    if i in comp_rows:
        continue
    print("".join(field[i][j] for j in range(W) if j not in comp_cols))

Submission status: Accepted

Solution code:
H, W=map(int, input().split())
A=[]
tate=[False]*W
for i in range(H):
  tmp=list(input())
  if "#" not in tmp:
    continue
  A.append(tmp)
  for j in range(W):
    if tmp[j]=="#":
      tate[j]=True

for i in range(len(A)):
  ans=[]
  for j in range(W):
    if tate[j]:
      ans.append(A[i][j])
  print("".join(ans))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
a = []
index = []
for i in range(H):
    array = list(input())
    if list(set(array)) != ['.']:
        a.append(array)

h = len(a)
w = len(a[0])
for i in range(w):
    judge = False
    for j in range(h):
        if a[j][i] == '#':
            judge = True
    
    if not judge:
        index.append(i)

cnt = 0
for i in index:
    for j in range(h):
        del a[j][i-cnt]
    cnt += 1
for i in a:
    print(''.join(i))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
S = [input() for i in range(h)]
A = []
for s in S:
	if '#' in s:
		A.append(s)
nh = len(A)
B = [''] * nh
for x in range(w):
	if any(a[x] == '#' for a in A):
		for y in range(nh):
			B[y] += A[y][x]
for b in B:
	print(b)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import numpy as np
H, W  = map(int, input().split())
data = [input().split() for _ in range(int(H))]
data_new = np.empty((0, W))
data_ = []
for i in data:
    for h in i[0]:
        data_.append(h)        
data_ = np.array(data_).reshape(H, W)

for i in data_:
    if np.any(i == "#"):
        data_new = np.concatenate([data_new, i.reshape(1, W)])
        
data_ = data_new.T
data_new = np.empty((0, data_.shape[1]))

for i in data_:
    if np.any(i == "#"):
        data_new = np.concatenate([data_new, i.reshape(1, data_.shape[1])])

data_new = data_new.T

for i in data_new:
    i = i.tolist()
    print(''.join(i))

Submission status: Accepted

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

for i in range(H):
    for j in range(W):
        if a[i][j] == '#':
            a[i][j] = 1
        else:
            a[i][j] = 0

a = np.array(a)

while True:
    flag = True
    for i in range(len(a)-1, -1, -1):
        if sum(a[i]) == 0:
            a = np.delete(a, i, 0)
            flag = False

    a = a.T
    for i in range(len(a)-1, -1, -1):
        if sum(a[i]) == 0:
            a = np.delete(a, i, 0)
            flag = False
    a = a.T

    if flag:
        break

ans = [['#']*len(a[0]) for _ in range(len(a))]
for i in range(len(a)):
    for j in range(len(a[i])):
        if a[i][j] == 0:
            ans[i][j] = '.'

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

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a2=[]
for i in range(h):
    a=list(input())
    if '#' in a:
        a2.append(a)
for i in range(w):
    x=[row[i] for row in a2]
    if '#' not in x:
        for j in range(len(a2)):
            a2[j][i]=''
for i in a2:
    print(*i,sep='')

Submission status: Accepted

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

d=[]
memo=[0]*W
for i in range(H):
  row=list(str(input()))
  if '#' in row:
    d.append(row)
  for j in range(W):
    if row[j] == '#':
      memo[j] = 1

for i in range(len(d)):
  for j in range(W):
    if memo[j] == 1:
      print(d[i][j],end='')
  print()

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
a=[]
for i in range(h):
  temp=list(map(str,input()))
  a.append(temp)
temph=[]
tempw=[]
for i in range(h):
  for j in range(w):
    if a[i][j]!=".":
      break
  else:
    temph.append(i)
for i in range(w):
  for j in range(h):
    if a[j][i]!=".":
      break
  else:
    tempw.append(i)
import numpy as np
tempnp=np.array(a)
for i in range(len(temph)):
  tempnp=np.delete(tempnp, temph[i]-i, 0)
for i in range(len(tempw)):
  tempnp=np.delete(tempnp, tempw[i]-i, 1)
for i in range(h-len(temph)):
  print("".join(tempnp[i]))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = []
c = 0
for i in range(h):
    b = list(input())
    if "#" in b:
        a.append(b)
        c += 1
d = []
for i in range(w):
    e = []
    for j in range(c):
        e.append(a[j][i])
    else:
        d.append(e)
f = []
g = 0
for i in range(w):
    if "#" in d[i]:
        f.append(d[i])
        g += 1
h = []
for i in range(c):
    e = []
    for j in range(g):
        e.append(f[j][i])
    else:
        h.append(e)
for i in range(c):
    print(*h[i], sep="")

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
A=[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:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

H, W = MAP()
a = [input() for _ in range(H)]

ans = []
tate = []
yoko = []

for i in range(H):
	if a[i].count("#") >= 1:
		yoko.append(i)

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

for y in yoko:
	tmp = ""
	for t in tate:
		tmp += a[y][t]
	ans.append(tmp)

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

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
l=[input() for i in range(h)]
m=[]
for i in range(h):
  if l[i]=='.'*w:
    m.append(i)
for x in m[::-1]:
  del l[x]
m=[]
for i in range(w):
  now=0
  for j in range(len(l)):
    if l[j][i]=='.':
      now+=1
  if now==len(l):
    m.append(i)
for x in m[::-1]:
  for i in range(len(l)):
    l[i]=l[i][:x]+l[i][x+1:]
[print(x) for x in l]

Submission status: Accepted

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

skip = []
for i in range(h):
  if a[i] == ["."] * w: skip.append(i)

a = list(zip(*a))
d = []
for i in range(w):
  if set(a[i]) == {"."}: d.append(i)
d.sort(reverse=True)
for i in d:
  a.pop(i)

a = list(zip(*a))
for i in range(h):
  if i in skip: continue
  else:
    print("".join(a[i]))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
a = [input() for _ in range(H)]

ans = []
tate = []
yoko = []

for i in range(H):
	if a[i].count("#") >= 1:
		yoko.append(i)

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

for y in yoko:
	tmp = ""
	for t in tate:
		tmp += a[y][t]
	ans.append(tmp)

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

Submission status: Accepted

Solution code:
import itertools
import math
import sys
from copy import copy
import numpy as np

h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
skip_col = []
skip_row = []
for i in range(h):
    ok = True
    for j in range(w):
        if (a[i][j] == '#'):
            ok = False
    if (ok):
        skip_col.append(copy(i))

for j in range(w):
    ok = True
    for i in range(h):
        if (a[i][j] == '#'):
            ok = False
    if (ok):
        skip_row.append(copy(j))

xw = w - len(skip_row)
xh = h - len(skip_col)
ans = [['x' for _ in range(xw)] for _ in range(xh)]
xi = 0
xj = 0
for i in range(h):
    xj = 0
    added = False
    for j in range(w):
        if (i not in skip_col and j not in skip_row):
            ans[xi][xj] = a[i][j]
            added = True
            xj += 1
    if added:
        xi += 1

for s in ans:
    print(''.join(s))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
A = []
b = ['.' for i in range(W)]
for i in range(H):
  a = list(input())
  if a != b:
    A.append(a)
m = len(A)
import numpy as np
A = np.array(A).T.tolist()
d = ['.' for i in range(m)]
C = []
for i in range(W):
  c = A[i]
  if c != d:
    C.append(c)
    
C = np.array(C).T.tolist()
n = len(C)
for i in range(n):
  ans="".join(C[i])
  print(ans)

Submission status: Accepted

Solution code:
import copy
H,W = map(int,input().split())
A = [list(input().strip()) for _ in range(H)]
while True:
    flag = 0
    for i in range(len(A)-1,-1,-1):
        fr = 0
        for j in range(len(A[0])):
            if A[i][j]=="#":
                fr = 1
                break
        if fr==0:
            B = [[0 for _ in range(len(A[0]))] for _ in range(len(A)-1)]
            for i1 in range(len(A)):
                if i1<i:
                    for j1 in range(len(A[0])):
                        B[i1][j1] = A[i1][j1]
                elif i1>i:
                    for j1 in range(len(A[0])):
                        B[i1-1][j1] = A[i1][j1]
            A = copy.deepcopy(B)
            flag = 1
    for j in range(len(A[0])-1,-1,-1):
        fc = 0
        for i in range(len(A)):
            if A[i][j]=="#":
                fc=1
                break
        if fc==0:
            B = [[0 for _ in range(len(A[0])-1)] for _ in range(len(A))]
            for j1 in range(len(A[0])):
                if j1<j:
                    for i1 in range(len(A)):
                        B[i1][j1] = A[i1][j1]
                elif j1>j:
                    for i1 in range(len(A)):
                        B[i1][j1-1] = A[i1][j1]
            A = copy.deepcopy(B)
            flag = 1
    if flag==0:break
for i in range(len(A)):
    print("".join(A[i]))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
block = [input() for _ in range(h)]
ok = [[False] * w for _ in range(h)]

for y in range(h):
    for x in range(w):
        if block[y][x] == '.':
            #print(y,x)
            nowy = 0
            nowx = 0
            flag = True
            while nowy < h:
                if block[nowy][x] == '.':
                    nowy += 1
                else:
                    flag = False
                    break
            if flag:
                for y_ in range(h):
                    ok[y_][x] = True
            flag = True
            while nowx < w:
                #print(nowx)
                if block[y][nowx] == '.':
                    nowx += 1
                else:
                    flag = False
                    break
            if flag:
                for x_ in range(w):
                    ok[y][x_] = True
ans = []
for y in range(h):
    a = ""
    for x in range(w):
        if ok[y][x] != True:
            a += block[y][x]
    if len(a) != 0:
        ans.append(a)
print(*ans,sep='\n')

Submission status: Accepted

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

del_h = []
del_w = []

for i, h in enumerate(a):
    if "#" not in h:
        del_h.append(i)
for j in range(W):
    judge = True
    for k in range(H):
        if a[k][j] == "#":
            judge = False
    if judge:
        del_w.append(j)
for i in range(H):
    ans = ""
    for j in range(W):
        if i in del_h or j in del_w:
            pass
        else:
            ans += a[i][j]
    if len(ans) > 0:    
        print(ans)

Submission status: Accepted

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

h, w = [int(x) for x in input().split()]
a = []
for _ in range(h):
    b = list(input().rstrip())
    if '#' in b:
        a.append(b)
h = len(a)
c = [1]*w
for i in range(w):
    flag = 1
    for j in range(h):
        if a[j][i] == "#":
            flag = 0
            break
    if flag:
        c[i] = 0
ans = []
for i in range(h):
    res = []
    for j in range(w):
        if c[j]:
            res.append(a[i][j])
    ans.append("".join(res))
for i in ans:
    print(i)

Submission status: Accepted

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

skip = []
for i in range(h):
  if a[i] == ["."] * w: skip.append(i)

a = list(zip(*a))
d = []
for i in range(w):
  if set(a[i]) == {"."}: d.append(i)
d.sort(reverse=True)
for i in d:
  a.pop(i)

a = list(zip(*a))
for i in range(h):
  if i in skip: continue
  else:
    print("".join(a[i]))

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
retu = [0 for i in range(w)]
gyou = [0 for i in range(h)]
lst = []
for i in range(h):
    ai = input()
    kuro = 0
    for j in range(w):
        if ai[j] == '#':
            kuro = 1
            retu[j] = 1
    if kuro == 1:
        gyou[i] = 1
    lst.append(ai)

ans = []
for i in range(h):
    if gyou[i] == 0: continue
    temp = ''
    for j in range(w):
        if retu[j] == 1:
            temp += lst[i][j]
    ans.append(temp)

for temp in ans:
    print(temp)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
A = []
for i in range(h):
    a = str(input())
    if a == '.'*w:
        continue
    else:
        A.append(a)

non_use = set()
for i in range(w):
    flag = True
    for j in range(len(A)):
        if A[j][i] == '#':
            flag = False
            break
    if flag:
        non_use.add(i)

ans = []
for i in range(len(A)):
    temp = ''
    for j in range(w):
        if j in non_use:
            continue
        else:
            temp += A[i][j]
    ans.append(temp)

for s in ans:
    print(s)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

H, W = map(int, input().split())
a = [input()[:-1] for _ in range(H)]
f = [False]*W

for i in range(W):
    l = []
    
    for j in range(H):
        l.append(a[j][i])
    
    if l==['.']*H:
        f[i] = True

for i in range(H):
    if a[i]=='.'*W:
        continue
    
    ans = []
    
    for j in range(W):
        if not f[j]:
            ans.append(a[i][j])
    
    print(''.join(ans))

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
mat = []
for i in range(h):
  g = list(input())
  if g.count(".") != w:
    mat.append(g)


for i in range(w-1, -1, -1):
  count = 0
  for j in range(len(mat)):
    if mat[j][i] == ".":
      count += 1
  if count == len(mat):
    for j in range(len(mat)):
      mat[j].pop(i)

for h in range(len(mat)):
  print("".join(mat[h]))

Submission status: Accepted

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

tmp1 = [i for i in a if set(i) != {"."}]
tmp2 = [list(i) for i in zip(*tmp1)]
tmp3 = [i for i in tmp2 if set(i) != {"."}]
ans = [list(i) for i in zip(*tmp3)]
for i in ans:
    print("".join(i))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
yoko=[input() for i in range(n)]
yokosiro=[0 if "#" in yoko[i] else 1 for i in range(n)]
tatesiro=[]
for i in range(m):
    ta=[0 if yoko[j][i]=="#" else 1 for j in range(n)]
    if 0 in ta:
        tatesiro.append(0)
    else:
        tatesiro.append(1)
for i in range(n):
    if yokosiro[i]==0:
        print("".join([yoko[i][j] for j in range(m) if tatesiro[j]==0]))

Submission status: Accepted

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

for w in range(W):
    g = [a[h][w] for h in range(H)]
    if set(g) == {"."}:
        for h in range(H):
            a[h][w] = ""

for h in range(H):
    g = a[h]
    if set(g) != {"."} and set(g) != {"", "."}:
        print("".join(g))

Submission status: Accepted

Solution code:
def remove_row(l):
  ret = []
  for row in l:
    s = row[0]
    if any([e == "#" for e in s]):
      ret.append(row)
      
  return ret

def remove_col(l,w):
  num_row = len(l)
  num_col = w
  ret = [[""] for _ in range(num_row)]
  for i in range(num_col):
    if any([l[j][0][i] == "#" for j in range(num_row)]):
      for k in range(num_row):
        ret[k] = [ret[k][0] + l[k][0][i]]
        
  return ret


h, w = map(int, input().split())
l = [input().split() for _ in range(h)]

l = remove_row(l)
l = remove_col(l,w)
for e in l:
  print(e[0])

Submission status: Accepted

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

remove_H = []
w_count = [0] * W
for h in range(H):
    if "#" in A[h]:
        remove_H.append(A[h])
        for i, w in enumerate(A[h]):
            if w == "#":
                w_count[i] += 1
remove_W = set([i for i, x in enumerate(w_count) if x != 0])
for h in remove_H:
    ans = [h[i] for i in range(W) if i in remove_W]
    print("".join(ans))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
s = [input() for _ in range(H)]
s2 = []

for x in s:
	if x == "." * W:
		continue
	s2.append(x)

#print(s2)

check = [1]*W

for i in range(len(s2)):
	for j in range(W):
		if s2[i][j] == "#":
			check[j] *= 0
#print(check)

for i in range(len(s2)):
	for j in range(W):
		if check[j] == 0:
			print(s2[i][j], end = "")
	print()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
a = [list(input()) for _ in [0]*h]
for j in range(w):
    if not any(a[i][j]=='#' for i in range(h)):
        for i in range(h):
            a[i][j] = ''
for i in a:
    if any(j=='#' for j in i):
        print(''.join(i))

Submission status: Accepted

Solution code:
def resolve():
	h, w = map(int, input().split())
	grid = []
	for _ in range(h):
		grid.append(list(input()))
	for i in range(h):
		removable = True
		for j in range(w):
			if grid[i][j] == '#':
				removable = False
				break
		if removable:
			for j in range(w):
				grid[i][j] = False

	for i in range(w):
		for j in range(h):
			removable = True
			if grid[j][i] == '#':
				removable = False
				break
		if removable:
			for j in range(h):
				grid[j][i] = False
	for r in grid:
		ans = ""
		for el in r:
			if el:
				ans += el
		if ans:
			print(ans)
resolve()

Submission status: Accepted

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

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

Submission status: Accepted

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

# print(hw)
yoko_new = []
for x in range(H):
    # print(hw[x])
    yoko_check = True
    for y in range(W):
        if hw[x][y] == "#":
            yoko_check = False
    if not yoko_check:
        yoko_new.append(hw[x])

yoko_new_len = len(yoko_new)

tate_new = [["-1" * W] * yoko_new_len]

z = 0
while z < len(yoko_new[0]):
    # for z in range(W):
    tate_check = True
    for w in range(yoko_new_len):
        if yoko_new[w][z] == "#":
            tate_check = False
    if tate_check:
        for w in range(yoko_new_len):
            yoko_new[w].pop(z)
    else:
        z += 1
for v in yoko_new:
    print("".join(v))

Submission status: Accepted

Solution code:
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
H,W = LI()
a = [S() for _ in range(H)]
a2,a3 = [],[]
for x in a:
    if '#' in x:
        a2.append(x)
for y in zip(*a2):
    if '#' in y:
        a3.append(y)
for z in zip(*a3):
    print(*z,sep='')

Submission status: Accepted

Solution code:
import numpy as np,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
H,W = LI()
a = np.array([[s for s in S()] for _ in range(H)])
a = a[(a=='#').any(axis=1)]
a = a.T
a = a[(a=='#').any(axis=1)]
a = a.T.tolist()
for x in a:
    print(*x,sep='')

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
grid = []
datah = []
dataw = []
for i in range(h):
    l = list(input())
    grid.append(l)
    if l.count("#") == 0:
        datah.append(i)
for j in range(w):
    for k in range(h):
        if grid[k][j] == "#":
            break
    else:
        dataw.append(j)
for i in range(h):
    if i in datah:
        continue
    print("".join([grid[i][n] for n in range(w) if not n in dataw]))

Submission status: Accepted

Solution code:
def removeRow(matrix):
    _matrix = []
    for i in range(len(matrix)):
        if max(matrix[i]) == 1:
            _matrix.append(matrix[i])
    return _matrix

def removeCol(matrix):
    r = len(matrix)
    c = len(matrix[0])
    rightRotatedMatrix = []
    for i in range(c):
        col = []
        for j in range(r-1, -1, -1):
            col.append(matrix[j][i])
        rightRotatedMatrix.append(col)    
    rightRotatedMatrix = removeRow(rightRotatedMatrix)
    r = len(rightRotatedMatrix)
    c = len(rightRotatedMatrix[0])
    matrix = []
    for i in range(c-1, -1, -1):
        row = []
        for j in range(r):
            row.append(rightRotatedMatrix[j][i])
        matrix.append(row)
    return matrix

def answer(matrix):
    matrix = removeRow(matrix)
    return removeCol(matrix)

r, c = map(int, input().split())
matrix = []
for _ in range(r):
    row = [i for i in input()]
    for i in range(len(row)):
        if row[i] == '#':
            row[i] = 1
        if row[i] == '.':
            row[i] = 0
    matrix.append(row)
    
matrix = answer(matrix)
for i in range(len(matrix)):
    row = []
    for j in range(len(matrix[i])):
        if matrix[i][j] == 1:
            row.append('#')
        else:
            row.append('.')
    print("".join(row))

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
a = []
for i in range(H):
  a.append(input())
cnt = 1
while cnt != 0:
  cnt = 0
  new = []
  for i in range(H):
    if a[i] == '.'*W:
      cnt += 1
    else:
      new.append(a[i])
  H = H - cnt
  cnt_2 = 0
  new_2 = ['' for _ in range(H)]
  for i in range(W):
    tmp = ''
    for j in range(H):
      tmp += new[j][i]
    if tmp == '.'*H:
      cnt_2 += 1
    else:
      for j in range(H):
        new_2[j] += tmp[j]
  cnt += cnt_2
  W = W - cnt_2
  a = new_2
for i in range(H):
  print(a[i])