시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 3 0 0 0.000%

문제

구역의 경계가 주어졌을 때, 각 구역을 채우는 프로그램을 작성하시오.

입력

입력은 테스트 케이스 여러개가 주어진다. 각 테스트 케이스의 첫째 줄에는 행의 개수 R, 열의 개수 C, 구역의 개수가 주어진다. 행은 제일 위가 1행이고, 열은 가장 왼쪽이 1열이다. 행은 최대 47행이고, 열은 최대 63행이다.

다음 둘째 줄부터는 각 구역의 설명이 주어진다. 구역의 설명의 첫째 줄에는 구역을 채우는데 사용할 알파벳, 시작하는 행 번호와 열 번호, 경계선의 개수가 주어진다. 경계선의 개수는 적어도 두 개이다. 알파벳은 중복되지 않으며, 다음 줄은 경계선을 설명하는 줄이다.

H A B
G   C
F E D

위와 같이 경계선을 시작점부터 시계방향으로 설명한다.

출력

각각의 테스트 케이스에 대해서, R개의 행, C개의 열로 구역을 모두 채운 결과를 출력한다. 구역이 아닌 곳은 마침표('.')로 출력한다.

다음과 같은 경우가 발생할 때는, 발생한 순서대로 구역을 채운 결과를 출력하기 전에 한 줄에 하나씩 출력한다. (아래 설명에서 A와 B는 해당하는 구역 알파벳으로 바꾸면 된다)

1. 경계선이 배열의 경계를 넘어갈 때는 다음과 같이 출력한다.

REGION A GOES OUTSIDE THE ARRAY

2. 경계선이 닫혀있지 않다면 다음과 같이 출력한다. 즉, 다시 시작점으로 돌아오지 않았을 때이다.

REGION A BOUNDARY IS NOT CLOSED

3. 구역 B의 경계가 이전에 채운 구역 A와 겹친다면, 다음과 같이 출력한다.

REGION B BOUNDARY INTERSECTS REGION A

각 테스트 케이스는 빈 줄로 구분한다.

예제 입력 1

2
20 40 4
B 3 21 22
CCDDDCBBBCCFFFFFGHHHHH
C 5 8 36
CCDCDDDEDEEFEFFFGFGGHGHHHAHAABABBBCB
D 10 24 38
CCCCCCEEEGGFEDCCEEEGGGGGGAAACCBAHGGAAA
A 2 2 3
CEH
10 20 4
A 4 6 10
GGAAACCEEE
B 6 16 30
CCCCCCCCCCCCEEEGGGGGGGGGGGGAAA
C 5 6 10
CCCCDDFFFG
D 6 2 10
AAACCEEEGG

예제 출력 1

........................................
.AA.....................................
..A.................BBB......BBB........
.....................BBB....BBB.........
.......CCC............BBB..BBB..........
.....CCCCCCC...........BBBBBB...........
....CCCCCCCCC...........BBBB............
...CCCCCCCCCCC...........BB.............
..CCCCCCCCCCCCC.........................
..CCCCCCCCCCCCC........DDDDDDD..........
.CCCCCCCCCCCCCCC.......DDDDDDD..........
.CCCCCCCCCCCCCCC.......DDDDDDD..........
.CCCCCCCCCCCCCCC.......DDDDDDD..........
..CCCCCCCCCCCCC...........D.............
..CCCCCCCCCCCCC...........D.............
...CCCCCCCCCCC.........DDDDDDD..........
....CCCCCCCCC..........DDDDDDD..........
.....CCCCCCC...........DDDDDDD..........
.......CCC.............DDDDDDD..........
........................................

REGION B GOES OUTSIDE THE ARRAY
REGION C BOUNDARY IS NOT CLOSED
REGION D BOUNDARY INTERSECTS REGION A
...AAA..............
...AAA..............
...AAA..............
...AAA..............
....................
....................
....................
....................
....................
....................
W3sicHJvYmxlbV9pZCI6IjI3NjIiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWFkNmNcdWM1ZWQgXHVjYzQ0XHVjNmIwXHVhZTMwIiwiZGVzY3JpcHRpb24iOiI8cD5cclxuXHRcdWFkNmNcdWM1ZWRcdWM3NTggXHVhY2JkXHVhY2M0XHVhYzAwIFx1YzhmY1x1YzViNFx1Yzg0Y1x1Yzc0NCBcdWI1NGMsIFx1YWMwMSBcdWFkNmNcdWM1ZWRcdWM3NDQgXHVjYzQ0XHVjNmIwXHViMjk0IFx1ZDUwNFx1Yjg1Y1x1YWRmOFx1YjdhOFx1Yzc0NCBcdWM3OTFcdWMxMzFcdWQ1NThcdWMyZGNcdWM2MjQuPFwvcD5cclxuIiwiaW5wdXQiOiI8cD5cclxuXHRcdWM3ODVcdWI4MjVcdWM3NDAgXHVkMTRjXHVjMmE0XHVkM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