RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0441

Replication

Platinum II 플래티넘 II
난이도
2s
시간 제한
256MB
메모리 제한
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\times N\) grid (\(3\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 \(D\) hours (\(1 \leq D \leq 10^9\)), every copy of the robot replicates
--- a robot at cell \((x,y)\) that replicates creates new copies in cells
\((x+1,y)\), \((x-1,y)\), \((x,y+1)\), and \((x,y-1)\); the original robot remains at
\((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.

Problem credits: Benjamin Qi

제약

SCORING

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

Problem credits: Benjamin Qi

입력 형식

The first line contains two space-separated integers \(N\) and \(D\). The next \(N\) lines of input each contain \(N\) 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..#
##########
##########
##########
##########
출력
15
설명

In the following diagrams, x's denote robots.

Locations that could be occupied by robots:

##########
#xxx.....#
#xxxx....#
#xxx.....#
##########
#xx..xxx.#
##########
##########
##########
##########

One possible sequence of events could be as follows:

  • FJ places the robot at the upper-left-most starting position.
  • The robot moves one unit to the right.
  • The robot replicates.
  • All robots move one unit to the right.
  • Another replication would cause a copy of the robot to move into a rock, so the process terminates.
##########    ##########    ##########    ##########
#........#    #........#    #.x......#    #..x.....#
#x.......#    #.x......#    #xxx.....#    #.xxx....#
#........#    #........#    #.x......#    #..x.....#
########## -> ########## -> ########## -> ##########
#........#    #........#    #........#    #........#
##########    ##########    ##########    ##########
##########    ##########    ##########    ##########
##########    ##########    ##########    ##########
##########    ##########    ##########    ##########
예제 2
입력
10 2
##########
#.#......#
#.#......#
#S.......#
#.#......#
#.#......#
##########
##########
##########
##########
출력
28
설명

Locations that could be occupied by robots:

##########
#x#.xxx..#
#x#xxxxx.#
#xxxxxxxx#
#x#xxxxx.#
#x#.xxx..#
##########
##########
##########
##########
예제 3
입력
10 2
##########
#.S#.....#
#..#.....#
#S.......#
#..#.....#
#..#.....#
##########
##########
##########
##########
출력
10
설명

Locations that could be occupied by robots:

##########
#xx#.....#
#xx#.....#
#xxx.....#
#xx#.....#
#x.#.....#
##########
##########
##########
##########
문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2020-2021 > December > Gold

태그

평가 및 의견

Replication

개요
출제자 난이도 Platinum II 플래티넘 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Replication

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8