본문 바로가기

IT/기타

백준 11723 집합

반응형

문제 링크 : https://www.acmicpc.net/problem/11723

언어 : python3



import sys
resultSet = 0
executeCount = sys.stdin.readline()

for i in range(0, int(executeCount)):
    operatorStr = sys.stdin.readline()
    executeOperator = operatorStr.split(" ")[0]
    executeNumber = 0

    if executeOperator != "all\n" and executeOperator != "empty\n":
        executeNumber = int(operatorStr.split(" ")[1]) - 1

    if executeOperator == "add":
        resultSet |= (1 << executeNumber)
    elif executeOperator == "remove":
        resultSet &= ~(1 << executeNumber)
    elif executeOperator == "check":
        if resultSet & (1 << executeNumber):
            print("1")
        else:
            print("0")
    elif executeOperator == "toggle":
        if resultSet & (1 << executeNumber):
            resultSet = (resultSet & ~(1 << executeNumber))
        else:
            resultSet |= (1 << executeNumber)
    elif executeOperator == "all\n":
        resultSet = (1 << 20) - 1
    elif executeOperator == "empty\n":
        resultSet &= 0



일단 비트연산자 또는 배열을 통해 푸는것을 추천


파이썬은 거의 처음이라 쫌 걸리긴했다ㅠㅠ




반응형