-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbj_15787.py
More file actions
32 lines (28 loc) · 813 Bytes
/
Copy pathbj_15787.py
File metadata and controls
32 lines (28 loc) · 813 Bytes
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
29
30
31
import sys
sys.stdin = open('bj_15787_in.txt', 'r')
input = sys.stdin.readline
n, m = map(int, input().strip().split())
trains = [0] * n
mask = (1<<20) -1 #20자리 비트
# print(mask)
# print(trains)
# 기차 좌석 배정
for _ in range(m):
cmd = input().strip().split()
# print(cmd)
op = cmd[0]
train = int(cmd[1]) -1
# print(train)
#명령어 분기
if op == '1': #승차
seat = int(cmd[2]) -1
trains[train] |= (1 << seat)
elif op == '2': #하차
seat = int(cmd[2]) -1
trains[train] &= ~(1 << seat)
elif op == '3': #한칸씩 +1, 20번째 사람은 하차
trains[train] = (trains[train] << 1) & mask
elif op == '4': #한칸씩 -1, 1번째 사람은 하차
trains[train] >>= 1
# print(trains)
print(len(set(trains)))