diff --git "a/\353\260\261\354\244\200/Gold/14503.\342\200\205\353\241\234\353\264\207\342\200\205\354\262\255\354\206\214\352\270\260/README.md" "b/\353\260\261\354\244\200/Gold/14503.\342\200\205\353\241\234\353\264\207\342\200\205\354\262\255\354\206\214\352\270\260/README.md" new file mode 100644 index 0000000..3354a85 --- /dev/null +++ "b/\353\260\261\354\244\200/Gold/14503.\342\200\205\353\241\234\353\264\207\342\200\205\354\262\255\354\206\214\352\270\260/README.md" @@ -0,0 +1,51 @@ +# [Gold V] 로봇 청소기 - 14503 + +[문제 링크](https://www.acmicpc.net/problem/14503) + +### 성능 요약 + +메모리: 34112 KB, 시간: 60 ms + +### 분류 + +구현, 시뮬레이션 + +### 제출 일자 + +2024년 10월 28일 20:27:58 + +### 문제 설명 + +
로봇 청소기와 방의 상태가 주어졌을 때, 청소하는 영역의 개수를 구하는 프로그램을 작성하시오.
+ +로봇 청소기가 있는 방은
로봇 청소기는 다음과 같이 작동한다.
+ +첫째 줄에 방의 크기
셋째 줄부터
로봇 청소기가 작동을 시작한 후 작동을 멈출 때까지 청소하는 칸의 개수를 출력한다.
+ diff --git "a/\353\260\261\354\244\200/Gold/14503.\342\200\205\353\241\234\353\264\207\342\200\205\354\262\255\354\206\214\352\270\260/\353\241\234\353\264\207\342\200\205\354\262\255\354\206\214\352\270\260.py" "b/\353\260\261\354\244\200/Gold/14503.\342\200\205\353\241\234\353\264\207\342\200\205\354\262\255\354\206\214\352\270\260/\353\241\234\353\264\207\342\200\205\354\262\255\354\206\214\352\270\260.py" new file mode 100644 index 0000000..c5a6bb5 --- /dev/null +++ "b/\353\260\261\354\244\200/Gold/14503.\342\200\205\353\241\234\353\264\207\342\200\205\354\262\255\354\206\214\352\270\260/\353\241\234\353\264\207\342\200\205\354\262\255\354\206\214\352\270\260.py" @@ -0,0 +1,56 @@ + +import sys +input = lambda: sys.stdin.readline().rstrip() +from collections import deque + +n, m = map(int, input().split()) +x, y, d = map(int, input().split()) +grid = [] +for _ in range(n): + grid.append(list(map(int, input().split()))) + +DIRTY_ROOM = 0 +CLEAN_ROOM = -1 +WALL = 1 +BACK = [(1, 0), (0, -1), (-1, 0), (0, 1)] # 방향; 북/동/남/서 +FRONT = [(-1, 0), (0, 1), (1, 0), (0, -1)] + + +def turn(d: int) -> int: # 반시계 방향 회전 + return (d + 3) % 4 + +cnt = 0 + +while True: + if grid[x][y] == DIRTY_ROOM: + cnt += 1 + grid[x][y] = CLEAN_ROOM + + has_dirty_room = False + for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]: + nx = x + dx + ny = y + dy + + if nx < 0 or nx >= n or ny < 0 or ny >= m: # 가장자리 + continue + + if grid[nx][ny] == DIRTY_ROOM: + has_dirty_room = True + break + + if has_dirty_room: # 조건3 + d = turn(d) + dx, dy = FRONT[d] + if (0 <= x + dx < n and 0 <= y + dy < m) and grid[x + dx][y + dy] == DIRTY_ROOM: + x += dx + y += dy + else: # 조건2 + dx, dy = BACK[d] + if (0 <= x + dx < n and 0 <= y + dy < m) and grid[x + dx][y + dy] != WALL: # 2-1 + x += dx + y += dy + else: # 2-2 + break + + +print(cnt)