Logo
(追記) (追記ここまで)

8356번 - Chessboard 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB207541.667%

문제

On an extremely large chess board many chessmen were located1 - all of them of the same colour. We say that a given chessman can capture specified position on the chess board, if the chessman can move to that position, particularly:

  • there is no chessman standing on destination position,
  • there are no chessmen on the way from the initial position to the destination (in case of a queen, a rook and a bishop).

No chessman can capture the position on which it is standing. Notice that a single position can be captured by multiple chessmen.

Write a program which:

  • reads a description of the chessboard from the standard input,
  • for each chessman determines the number of positions being captured by that chessman,
  • writes the result to the standard output.

1You can read more about chess and chessmen here: http://en.wikipedia.org/wiki/Chess_piece.

입력

In the first line of the input there are two integers n and m (1 ≤ n ≤ 200 000, 1 ≤ m ≤ 109), separated with a single space and representing the number of chessmen located on the square chessboard and its dimension m. Each of the n following lines is of the format "F x y", where F is a letter representing:

  • G - bishop,
  • H - queen,
  • K - king,
  • S - knight,
  • W - rook,

and (x, y) is a location of the chessman (1 ≤ x, ym). No two chessmen are located in the same position.

출력

The output should consist of n lines. i'th line should contain one integer, representing the number of positions being captured by i'th chessman from the input.

제한

예제 입력 1

6 5
K 5 5
G 4 1
W 1 3
K 2 3
H 2 2
S 3 3

예제 출력 1

3
2
4
5
7
7

힌트

The image above represents the chessboard from the sample input. Lines of different style represent positions being captured by chessmen. The possible destinations of the knight are represented by big dots.

출처

Contest > Algorithmic Engagements > PA 2008 5-4번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /