Mirror Maze

시간 제한1초메모리 제한2048 MB

요약
거울 격자의 경계 2(R+C)개 위치에서 레이저를 쏠 때, 모든 거울을 맞히는 시작 위치의 수를 구한다.
난이도

보통10점 중 6점

유형
시뮬레이션, 그래프, 구현
정답자
아직 제출이 없습니다

문제

You are given a grid of RR rows (numbered from 11 to RR from north to south) and CC columns (numbered from 11 to CC from west to east). Every cell in this grid is a square of the same size. The cell located at row rr and column cc is denoted as (r,c)(r, c). Each cell can either be empty or have a mirror in one of the cell’s diagonals. Each mirror is represented by a line segment. The mirror is type 11 if it is positioned diagonally from the southwest corner to the northeast corner of the cell, or type 22 for the other diagonal.

These mirrors follow the law of reflection, that is, the angle of reflection equals the angle of incidence. Formally, for type 11 mirror, if a beam of light comes from the north, south, west, or east of the cell, then it will be reflected to the west, east, north, and south of the cell, respectively. Similarly, for type 22 mirror, if a beam of light comes from the north, south, west, or east of the cell, then it will be reflected to the east, west, south, and north of the cell, respectively.

You want to put a laser from outside the grid such that all mirrors are hit by the laser beam. There are 2⋅(R+C)2 \cdot (R + C) possible locations to put the laser:

  • from the north side of the grid at column cc, for 1≤c≤C1 ≤ c ≤ C, shooting a laser beam to the south;
  • from the south side of the grid at column cc, for 1≤c≤C1 ≤ c ≤ C, shooting a laser beam to the north;
  • from the east side of the grid at row rr, for 1≤r≤R1 ≤ r ≤ R, shooting a laser beam to the west; and
  • from the west side of the grid at row rr, for 1≤r≤R1 ≤ r ≤ R, shooting a laser beam to the east.

Determine all possible locations for the laser such that all mirrors are hit by the laser beam.

입력

The first line consists of two integers RR CC (1≤R,C≤2001 ≤ R, C ≤ 200).

Each of the next RR lines consists of a string S_rS\_r of length CC. The ccth character of string S_rS\_r represents cell (r,c)(r, c). Each character can either be . if the cell is empty, / if the cell has type 11 mirror, or \ if the cell has type 22 mirror. There is at least one mirror in the grid.

출력

Output a single integer representing the number of possible locations for the laser such that all mirrors are hit by the laser beam. Denote this number as kk.

If k>0k > 0, then output kk space-separated strings representing the location of the laser. Each string consists of a character followed without any space by an integer. The character represents the side of the grid, which could be N, S, E, or W if you put the laser on the north, south, east, or west side of the grid, respectively. The integer represents the row/column number. You can output the strings in any order.

예제3

  1. 예제 1

    입력
    4 4
    .//.
    .\\.
    .\/.
    ....
    
    예상 출력
    2
    N3 W2
    
  2. 예제 2

    입력
    4 6
    ./..\.
    .\...\
    ./../\
    ......
    
    예상 출력
    2
    E3 S2
    
  3. 예제 3

    입력
    4 4
    ....
    ./\.
    .\/.
    ....
    
    예상 출력
    0