b_스위치켜고끄기_1244

source www.acmicpc.net/problem/1244
type 📌 개발노트
topics 600-알고리즘 & 코딩테스트 601 구현 & 완전탐색
types 문제풀이
정답여부 성공

문제

스위치 개수
1 ~ 스위치개수 이하 자연수
1 on ,0 off
if 남, 스위치 번호가 받은 수의 배수면 스위치 상태를 바꿈
if 여, 스위치 번호 == 받은수 중심으로 좌우 대칭이면서 가장 많은 스위치를 포함한 구간의 스위치 상태를 바꿈 자기자신도 바꿈

걍구현 비트연산자 토글할때 xor 즉 연산자 ^를 쓰면된다는 걸 알았다.

import sys
swi_n=int(sys.stdin.readline().strip()) # 스위치 수
switches = list(map(int,sys.stdin.readline().strip().split()))
stu_n = int(sys.stdin.readline().strip())

def change_switches(arr,stu_g,stu_s):
    if stu_g == 1: # 남자
        for i in range(len(arr)):
            if (i+1)%stu_s == 0:
                arr[i] ^= 1 else : # 여자
        stu_s -= 1 # 이제부턴 인덱스쓸꺼라 ㄱㅊ
        arr[stu_s] ^= 1 
        for i in range(1,stu_s+1):
            left = stu_s - i
            right = stu_s + i

            if -1 <left and right<len(arr):
                if arr[left] == arr[right]:
                    arr[left] ^= 1
                    arr[right] ^= 1
                else:
                    break
            else:
                break

while stu_n>0:
    student = list(map(int,sys.stdin.readline().strip().split()))
    stu_n -= 1
    change_switches(switches,student[0],student[1])

ans = ""
start = 0
swit_leng =len(switches)
while start<swit_leng:
    end = start+20
    if end>swit_leng:
        end = swit_leng
    ans+=(' '.join(map(str,switches[start:end])))
    ans+='\n'
    start += 20
print(ans)