Baekjoon #14891

Baekjoon #14891

1개의 풀이 · Python

문제 원문 보기 ↗

SOLUTION INFO

Python · main.py

main.py
import sys
from collections import deque

def input():
    return sys.stdin.readline().rstrip()

arr = []
ans = 0

for i in range(4):
    arr.append(deque(input()))

K = int(input())

for i in range(K):
    queue = deque()
    a, b = map(int, input().split())
    visited = [0] * 4
    queue.append((a-1,b,arr[a-1][6],arr[a-1][2]))
    visited[a-1] = 1
    arr[a-1].rotate(b)
    while queue:
        n,d,l,r = queue.popleft()
        if n-1 >= 0 and arr[n-1][2] != l and visited[n-1] == 0:
            visited[n-1] = 1
            queue.append((n-1, -d, arr[n-1][6], arr[n-1][2]))
            arr[n-1].rotate(-d)
        if n+1 < 4 and arr[n+1][6] != r and visited[n+1] == 0:
            visited[n+1] = 1
            queue.append((n+1, -d, arr[n+1][6], arr[n+1][2]))
            arr[n+1].rotate(-d)

for i in range(4):
    if arr[i][0] == '1':
        ans += 2 ** i

print(ans)

SOLUTION DESCRIPTION

풀이 설명

등록된 풀이 설명이 없습니다.