0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ABC107 B - Candles diff 茶は焦るかも

Posted at

abc107_1.png
abc107_2.png
abc107_3.png
abc107_4.png

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)。コメントの**"ココ"** をご覧ください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?