구현문제는 난이도와 수고에 비해 그냥 적용 알고리즘이 접하기 쉽다는 이유로 책정난이도가 너무 낮은 것 같다.
BFS로 풀었다.
import sys
input = sys.stdin.readline
from collections import deque
from copy import deepcopy
def is_rotate(cur_gire,next_gire):
if next_gire==cur_gire+1:
if check_rotate[cur_gire][2]!=check_rotate[next_gire][6]:
return True
elif next_gire==cur_gire-1:
if check_rotate[next_gire][2]!=check_rotate[cur_gire][6]:
return True
return False
def do_rotate(cur_gire,cur_dir):
queue=[]
queue.append([cur_gire,cur_dir])
finished=[False]*4
gires[cur_gire].rotate(cur_dir)
finished[cur_gire] = True
while queue:
cur_gire,cur_dir = queue.pop()
for next_gire in (cur_gire+1,cur_gire-1):
if 0<=next_gire<4 and not finished[next_gire]:
if is_rotate(cur_gire,next_gire):
queue.append([next_gire,-cur_dir])
gires[next_gire].rotate(-cur_dir)
finished[next_gire] = True
gires = []
for _ in range(4):
q=deque()
temp = list(map(int,list(input().rstrip())))
for num in temp:
q.append(num)
gires.append(q)
K = int(input())
for _ in range(K):
gire_num,dir = map(int,input().split())
check_rotate=deepcopy(gires)
do_rotate(gire_num-1,dir)
score=[1,2,4,8]
total=0
for i in range(4):
total+=gires[i][0]*score[i]
print(total)
'practivceAlgorithm > 백준' 카테고리의 다른 글
[백준][Python] 15810 풍선공장 (0) | 2021.08.08 |
---|---|
[백준][Python] 1341폴리오미노 (1) | 2021.08.07 |
[백준][Python] 1074 Z (0) | 2021.08.06 |
[백준][Python] 1316 그룹단어체커 (0) | 2021.08.06 |
[백준][Pyhton] 9489 사촌 (0) | 2021.08.06 |