ABC107 B - Candles diff 茶は焦るかも
5896 ワード
B 問題の diff 茶に初チャレンジ。
試験当日で、このレベルが来ると自分なら焦ると思います。
Candles.py
H,W = map(int,input().split())
A = [list(input()) for _ in range(H)]
lisA = []
h = 0
for h in range(H):
if A[h].count(".") != W:
lisA.append(A[h])
#print(lisA,len(lisA))
memo = []
for w in range(W):
cnt = 0
for h in range(len(lisA)):
#print(lisA[h][w],h,w)
if lisA[h][w] == ".":
cnt += 1
if cnt == len(lisA):
memo.append(w)
memo = set(memo)# <= ココ
ans =[]
for h in range(len(lisA)):
ans.append([])
for w in range(W):
if w not in memo:# <= ココ
ans[h].append(lisA[h][w])
#print(ans)
for i in range(len(ans)):
print("".join(ans[i]))
in 演算子は set は計算量 O(1)。コメントの"ココ" をご覧ください。
Author And Source
この問題について(ABC107 B - Candles diff 茶は焦るかも), 我々は、より多くの情報をここで見つけました https://qiita.com/AKpirion/items/5186bb31a7babe39b7b0著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .