풀이
메모리제한이 걸려있는 문제라 비트마스킹이라는 새로운 개념을 배워 적용했다.
Pypy3 로 제출했을 경우 메모리초과가 떠서 Python3 로 제출했더니 무리없이 통과했다.
소스코드
import sys
input = sys.stdin.readline
M = int(input())
S = 0
for _ in range(M):
inp = input()
command = inp.split()[0]
if command == "add":
S |= (1 << int(inp.split()[1]))
elif command == "remove":
S &= ~(1 << int(inp.split()[1]))
elif command == "remove":
S &= ~(1 << int(inp.split()[1]))
elif command == "check":
if S & (1 << int(inp.split()[1])):
print(1)
else:
print(0)
elif command == "toggle":
S ^= (1 << int(inp.split()[1]))
elif command == "all":
S = (1 << 21) - 1
elif command == "empty":
S = 0