b_집합_11723

source www.acmicpc.net/problem/11723
type 📌 개발노트
topics 600-알고리즘 & 코딩테스트 605 비트마스킹 601 구현 & 완전탐색
types 문제풀이
정답여부 시간초과

문제

내답
집합으로 단순구현하였는데 틀렷다.

import sys

input = sys.stdin.readline
N = int(input().strip())
arr = set([])
output = ""
for _ in range(N):
    data=input().strip()
    if data == "all":
        arr = set( [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"])
    elif data == "empty":
        arr.clear()
    else:
        op,num = data.split()
        if op == "add":
            arr.add(num)
        elif op == "check":
            output += ("1\n" if num in arr else "0\n")
        elif op == "remove":
            if num in arr:
                arr.remove(num)
        elif op == "toggle":
            if num in arr:
                arr.remove(num)
            else:
                arr.add(num)

print(output)

print합쳐서해서메모리초과난듯용;;

import sys

input = sys.stdin.readline
N = int(input().strip())
s = 0b0
output = ""
for _ in range(N):
    data=input().strip()
    # print("s",bin(s))
    if data == "all":
        s = 0b111111111111111111111
    elif data == "empty":
        s = 0b0
    else:
        op,num = data.split()
        num = int(num)
        if op == "add":
            s = s | (0b1<<num)
        elif op == "check":
            if s & (0b1<<num):
                print(1)
            else:
                print(0)
        elif op == "remove":
            s= s & ~(0b1<<num)
        elif op == "toggle":
            s = s ^ (0b1<<num)