CIJEVI | 프로그래밍의 벗 PivotOJ
PivotOJ

CIJEVI

시간 제한: 1000ms메모리 제한: 128MB출처: CHC 2009 Regional Competition - JuniorsBOJ 2931
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

To help design the new gas pipeline which will be used to deliver Russian gas to Croatia, Zagreb and Moscow are using the computer game Pipe Mania. In the game, Europe is divided into R rows and C columns. Each cell can be empty or contain one of the seven basic pipeline building blocks:

[이미지 1] [이미지 2] [이미지 3] [이미지 4] [이미지 5] [이미지 6] [이미지 7]
Block '|' Block '-' Block '+' Block '1' Block '2' Block '3' Block '4'

Gas flows from Moscow to Zagreb. Gas can flow in either direction through the building blocks. Block '+' is special in that gas must flow in two directions (one vertical, one horizontal), as in the following example:

[이미지 8]

Work on the new pipeline had already started when it was found that malicious hackers got hold of the plan and erased exactly one building block from the plan i.e. replaced it with an empty cell. 

Write a program that determines where the block was erased from and what type it was. 

입력

The first line contains two integers R and C, the dimensions of Europe (1 ≤ R, C ≤ 25). 

The following R lines contain the plan, each consisting of exactly C characters. The characters are: 

  • Period ('.'), representing an empty cell; 
  • The characters '|' (ASCII 124), '-', '+', '1', '2', '3', '4', representing the building block types; 
  • The letters 'M' and 'Z', representing Moscow and Zagreb. Each of these will appear exactly once in the plan. 

The flow of gas will be uniquely determined in the input; exactly one building block will be adjacent to each of Moscow and Zagreb. Additionally, the plan will not have redundant blocks i.e. all blocks in the plan must be used after the missing block is added. 

The input will be such that a solution will exist and it will be unique. 

출력

Output the row and column of the erased block, and the type of the block (one of the seven characters as in the input). 

예제

예제 1

입력
3 7
.......
.M-.-Z.
.......
출력
2 4 -

예제 2

입력
3 5
..1-M
1-+..
Z.23.
출력
2 4 4

예제 3

입력
6 10
Z.1----4..
|.|....|..
|..14..M..
2-+++4....
..2323....
..........
출력
3 3 |
코드를 제출하려면 로그인하세요.