doubleyyh   2년 전

많이 배우겠습니다. 파린이입니다.

제 코드인데요. 제가 아직 c스타일의 코딩을 하고 있는 것 같습니다. 메모리를 줄이기 위해서 이 코드에서 파이써닉하게 고칠 수 있는 방법이 있을까요?? 

감사합니다. 

import sys

N, M = map(int, sys.stdin.readline().strip().split())
truthPeople = list(map(int, sys.stdin.readline().strip().split()))
arry = [-1 for _ in range(N+1)]

c = M
partyPeople = [[] for _ in range(M)]
while c > 0:
    c -= 1
    partyPeople[c] = list(map(int, sys.stdin.readline().strip().split()))
    for i in range(2, len(partyPeople[c])):
        arry[partyPeople[c][i]] = partyPeople[c][1]

tempList = []
for i in range(1, N + 1):
    t = list()
    tt = i
    while tt != -1:
        t.append(tt)
        tt = arry[tt]
    f = False
    for ttt in t:
        for tl in tempList:
            if ttt in tl:
                f = True
                for tttt in t:
                    tl.add(tttt)
                break

    if f is False:
        tempList.append(set(t))

cnt = 0
for p in partyPeople:
    t = tuple()
    for pp in range(1, len(p)):
        for tt in tempList:
            if p[pp] in tt:
                t = tt
                break
    flag = False
    for tttttt in range(1, len(truthPeople)):
        if truthPeople[tttttt] in t:
            flag = True
            break
    if flag is False:
        cnt += 1

print(cnt)





doubleyyh   2년 전

정성스러운 답변 정말 감사합니다! ㅠㅠ 

doubleyyh   2년 전

혹시 메모리 초과는 어떻게 해결해야되는지 알 수 있을까요???

댓글을 작성하려면 로그인해야 합니다.