15685번 – 드래곤 커브

문제

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

풀이

코드

from copy import deepcopy

n = int(input())
curves = [list(map(int, input().split())) for _ in range(n)]
board = [[0]*102 for _ in range(102)]
dyx = [(0, 1), (-1, 0), (0, -1), (1, 0)]
rotate = [1, 2, 3, 0]

def findSquares():
  count = 0
  dyx = [(0, 1), (1, 0), (1, 1)]
  for y in range(len(board)):
    for x in range(len(board[y])):
      if board[y][x] == 1:
        hasSquare = True
        for dy, dx in dyx:
          _y, _x = (y+dy, x+dx)
          if board[_y][_x] != 1:
            hasSquare = False
            break
        if hasSquare is True: count += 1
  return count

def drawCurve(c):
  x, y, d, g = c
  dy, dx = dyx[d]
  # 0세대는 미리 그려놓는다
  board[y][x] = 1
  y, x = (y+dy, x+dx)
  board[y][x] = 1
  history = [d]
  for i in range(g):
    h = deepcopy(history)
    while(h):
      d = h.pop()
      rd = rotate[d]
      dy, dx = dyx[rd]
      y, x = (y+dy, x+dx)
      board[y][x] = 1
      history.append(rd)

def answer():
  for c in curves: drawCurve(c)
  count = findSquares()
  print(count)
  
answer()

Leave a Reply

Your email address will not be published.