반응형
[문제 출처]
https://www.acmicpc.net/problem/21918
21918번: 전구
$N$개의 전구가 있고 맨 왼쪽에 있는 전구를 첫 번째라고 하자. 전구의 상태는 두 가지가 있으며 이를 숫자로 표현한다. $1$은 전구가 켜져 있는 상태를 의미하고, $0$은 전구가 꺼져 있는 상태를
www.acmicpc.net
[문제 풀이]
import sys
input = sys.stdin.readline
n,m = map(int, input().split())
bulb = list(map(int,input().split()))
for i in range(m):
inst = list(map(int, input().split()))
if inst[0] == 1:
bulb[inst[1]-1] = inst[2]
elif inst[0] == 2:
for j in range(inst[1]-1, inst[2]):
if bulb[j] == 0:
bulb[j] = 1
else:
bulb[j] = 0
elif inst[0] == 3:
for j in range(inst[1]-1, inst[2]):
if bulb[j] == 1:
bulb[j] = 0
elif inst[0] == 4:
for j in range(inst[1]-1, inst[2]):
if bulb[j] == 0:
bulb[j] = 1
print(*bulb)
반응형
'알고리즘 > python' 카테고리의 다른 글
[python/파이썬] 백준 15990 1, 2, 3 더하기 5 (0) | 2022.07.20 |
---|---|
[python/파이썬] 백준 20546 기적의 매매법 (0) | 2022.07.19 |
[python/파이썬] 백준 14430 자원 캐기 (0) | 2022.07.18 |
[python/파이썬] 백준 11060 점프 점프 (0) | 2022.07.18 |
[python/파이썬] 백준 1660 캡틴 이다솜 (0) | 2022.07.15 |