eaz_coding

[Baekjoon] 14891 톱니바퀴 본문

eaz_algorithm

[Baekjoon] 14891 톱니바퀴

eaz_silver 2024. 11. 18. 23:13

문제

https://www.acmicpc.net/problem/14891

 


풀이

import sys
input = sys.stdin.readline

wheel = [list(input().strip()) for _ in range(4)]

k = int(input())

def check(now, i, directions):
    if i == 2:
        if now < 3 and wheel[now][i] != wheel[now+1][6]:
            directions[now+1] = -directions[now]
            directions = check(now+1, i, directions)
    elif i == 6:
        if now > 0 and wheel[now][i] != wheel[now-1][2]:
            directions[now-1] = -directions[now]
            directions = check(now-1, i, directions)
    return directions

def move(before, direction):
    result = before
    if direction == 1:
        result = [before[7]] + before[:7]
    elif direction == -1:
        result = before[1:] + [before[0]]
    return result

        
for _ in range(k):
    n, d = map(int, input().split())
    n -= 1

    directions = [0] * 4
    directions[n] = d
    directions = check(n, 2, directions)
    directions = check(n, 6, directions)

    for i in range(4):
        wheel[i] = move(wheel[i], directions[i])

answer = 0
for i in range(4):
    if wheel[i][0] == "1":
        answer += 2**i
print(answer)

'eaz_algorithm' 카테고리의 다른 글

[Baekjoon] 1167번 트리의 지름  (0) 2024.11.21
[Baekjoon]9019번 DSLR  (0) 2024.11.20
[Baekjoon] 1300 K번째 수  (0) 2024.11.16
[Baekjoon] 1904번 01타일  (0) 2024.11.15
[Baekjoon] 2805 나무 자르기  (1) 2024.11.14