티스토리 뷰
https://www.acmicpc.net/problem/1244
단순 구현문제이지만, 파이썬 입력받는 코드가 익숙하지 않아 많이 헤맸다..
import sys
N = 0
switches = []
students = 0
def solve():
init()
switch()
answer()
def init():
global N, switches, students
N = int(input())
switches = [-99] + list(map(int, input().split()))
students = int(input())
return
def switch():
global N, switches, students
for _ in range(students):
gender, switch_number = list(map(int, input().split()))
if gender == 1:
for i in range(switch_number, N + 1, switch_number):
change(i)
else:
change(switch_number)
move = 1
while True:
left = switch_number - move
right = switch_number + move
if left < 1 or right > N:
break
if switches[left] == switches[right]:
change(left)
change(right)
move +=1
else:
break
def change(switch_number):
global switches
if switches[switch_number] == 1:
switches[switch_number] = 0
else:
switches[switch_number] = 1
def answer():
global switches
for i in range(1, N + 1):
print(switches[i], end=" ")
if i % 20 == 0:
print()
if __name__ == '__main__':
solve()
'알고리즘 > 문제' 카테고리의 다른 글
실버III. 백준1904 01타일 (0) | 2022.04.09 |
---|---|
실버III. 백준 11727 2 x N 타일링 2 (0) | 2022.04.08 |
실버V. 백준 1059 좋은구간 (0) | 2022.04.04 |
브론즈II. 백준10093 숫자 (0) | 2022.03.30 |
실버IV. 백준1676 팩토리얼 0의 개수 (0) | 2021.12.27 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- https://react.vlpt.us/basic/11-render-array.html
- Co
- https://subicura.com/2017/01/19/docker-guide-for-beginners-1.html
- https://jwprogramming.tistory.com/52
- https://react.vlpt.us/
- ㄴ
- https://velog.io/@juno7803/React%EA%B0%80-%ED%83%9C%EC%96%B4%EB%82%9C-%EB%B0%B0%EA%B2%BD
- https://wikidocs.net/68
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함