#498
Unrated
Replication
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

The ill-fated result of watching too many "do it yourself" engineering videos on the web, Farmer John has accidentally released a self-replicating robot on his farm!

The farm can be represented by an N×NN\times N grid (3N10003\le N\le 1000) where each grid cell is either empty or filled with rock, and all border squares are filled with rock. Some non-rock cells are designated as possible starting locations for the robot.

Farmer John initially places the robot at one of the possible starting positions. In every hour that follows, all copies of the robot move in one coordinated mass in the same direction, either north, south, east, or west. After every DD hours (1D1091 \leq D \leq 10^9), every copy of the robot replicates --- a robot at cell (x,y)(x,y) that replicates creates new copies in cells (x+1,y)(x+1,y), (x1,y)(x-1,y), (x,y+1)(x,y+1), and (x,y1)(x,y-1); the original robot remains at (x,y)(x,y). Over time, multiple robots might come to occupy the same cell.

If moving or replicating would cause any of the robots to move into a rock, then all robots shut down immediately. Note that this implies that the robots must eventually shut down, due to the border of the farm being rock.

Help the cows figure out the number of empty squares that could potentially at some point in time hold a robot.

입력

The first line contains two space-separated integers NN and DD. The next NN lines of input each contain NN characters. Each character is one of '.', 'S', or '#'. '.' and 'S' both represent empty cells, with 'S' denoting a possible starting position for the robot. '#' denotes a rock.

All characters in the first and last row and first and last column are '#'.

출력

An integer counting the number of cells that could at some point in time hold a robot.

예제 입력 1

10 1
##########
#........#
#S.......#
#........#
##########
#S....S..#
##########
##########
##########
##########

예제 출력 1

15

예제 입력 2

10 2
##########
#.#......#
#.#......#
#S.......#
#.#......#
#.#......#
##########
##########
##########
##########

예제 출력 2

28

예제 입력 3

10 2
##########
#.S#.....#
#..#.....#
#S.......#
#..#.....#
#..#.....#
##########
##########
##########
##########

예제 출력 3

10

점수

Test cases 4-5 satisfy D=109D=10^9.Test cases 6-8 satisfy D=1D=1.Test cases 9-12 satisfy N100N\le 100.Test cases 13-20 satisfy no additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.