포럼
문제 ICPC00276

D. Deceptive Directions

설명

You find yourself on a remote island, searching for a legendary lost treasure. However, despite having gotten your hands on directions leading straight to the treasure, you have a problem. It turns out you have a saboteur in your expedition, and that at some point they edited the precious directions so they might no longer lead to the treasure.

The island can be viewed as a rectangular grid, and the instructions are a sequence of east/west/north/south steps to take in this grid, from a given starting position. These instructions lead straight to the treasure (but may involve walking around obstacles) in the sense that there is no shorter way of reaching the treasure. However, the saboteur has arbitrarily replaced each step of the instructions by a step in one of the other three directions. In other words, any "west" step has been replaced by "east", "north" or "south". This replacement has been done independently for each step, so one "west" may have been replaced by "north" and another by "south", and so on.

Because of this sabotage, the instructions seem pretty useless. But maybe they can still be used to narrow down the search. Write a program to find all possible locations of the treasure.

제약
입력 형식

The first line of input consists of two integers \(w\) and \(h\) ($3 \le
w, h \le 1000\(), the\ width\ and\ height\ of\ the\ map. Then\ follow \)h\( lines, each\ containing \)w$ characters, describing the map. Each such character is either a '.' symbolizing a walkable space, '#' symbolizing an obstacle such as a body of water, dense forest, or a mountain, or 'S' symbolizing the starting point of the directions.

Finally, there is a line containing a string \(I\) ($1 \le |I| \le
10^5$) consisting only of the characters 'NWSE', giving the faulty instruction sequence.

The map has exactly one 'S' and its boundary consists only of obstacle cells. The faulty instruction sequence is such that there is at least one possible location of the treasure.

출력 형식

Output the map in the same format as the input (without the first line specifying the dimensions), with all possible locations of the treasure indicated by exclamation marks ('!').

예제 1
입력
5 5
#####
#...#
#.S.#
#...#
#####
N
출력
#####
#...#
#!S!#
#.!.#
#####
예제 2
입력
7 5
#######
#..#..#
#..S..#
#..#..#
#######
ESS
출력
#######
#!.#..#
#..S..#
#..#..#
#######
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC NCPC 2021

평가 및 의견

D. Deceptive Directions

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

D. Deceptive Directions

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