본문 바로가기
python-algorithm

백준 11723 집합

by 무적김두칠 2023. 12. 23.

https://www.acmicpc.net/problem/11723

 

11723번: 집합

첫째 줄에 수행해야 하는 연산의 수 M (1 ≤ M ≤ 3,000,000)이 주어진다. 둘째 줄부터 M개의 줄에 수행해야 하는 연산이 한 줄에 하나씩 주어진다.

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import sys
 
 
if __name__ == '__main__':
    m = int(sys.stdin.readline())
    s = set()
    for i in range(m):
        operation = list(sys.stdin.readline().strip().split())
        if len(operation) == 1:
            if operation[0== 'all':
                s = set([i for i in range(121)])
            else:
                s = set()
        else:
            if operation[0== 'add':
                s.add(int(operation[1]))
            elif operation[0== 'remove':
                s.discard(int(operation[1]))
            elif operation[0== 'check':
                if int(operation[1]) in s:
                    print(1)
                else:
                    print(0)
            elif operation[0== 'toggle':
                if int(operation[1]) in s:
                    s.discard(int(operation[1]))
                else:
                    s.add(int(operation[1]))
cs

입력을 readline으로 해주셔야 속도 초과가 안날거같네요옹

반응형

'python-algorithm' 카테고리의 다른 글

백준 4388 받아올림  (0) 2023.12.27
백준 6550 부분 문자열  (2) 2023.12.23
백준 30045 ZOAC 6  (0) 2023.12.20
백준 30468 호반우가 학교에 지각한 이유 1  (0) 2023.12.20
백준 1120 문자열  (1) 2023.12.06

댓글