Patchwork

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

Adam’s grandmother has a birthday coming up and he wants to make her a beautiful patchwork quilt as a present. He has created a collection of patch designs that he will sew onto the quilt. However, he is having trouble deciding exactly where to place his patches. His current procedure is to sew on all patches in a given configuration, determine if he likes the way it looks, and cut them all off if he doesn’t. This is highly inefficient and Adam is running out of time.

Adam starts with a rectangular white cloth to be used as the base for his quilt and has a collection of possible patch types. Each patch type is a rectangular piece of cloth with a specified design. Fortunately, Adam has come prepared and he has an unlimited quantity of every patch type. Adam has asked you to write a program to determine what the cloth will look like after sewing the patches on in a specific order and in specific locations. Note that Adam cuts off excess fabric that hangs off the edge of the quilt’s base so your program should do the same.

Help Adam by writing a program to output the completed quilt.

입력

The first line of input consists of two integers R,CR,C (1R,C1001≤R,C≤100) giving the dimensions of the quilt. Initially, this quilt is white and is represented by a grid with RR rows and CC columns where each entry is the character ‘.’ (a period) representing white.

The second line contains a single integer NN (1N1001≤N≤100), which is the number of different patch types. The following describes the patches:

  • The first line in the description of the iith patch type consists of two integers r_i,c_ir\_i,c\_i (1r_i,c_i1001≤r\_i,c\_i≤100) giving the number of rows r_ir\_i and columns c_ic\_i in this patch.
  • Then r_ir\_i lines follow, each containing c_ic\_i non-whitespace ASCII characters which describes the iith patch type.

The next line contains a single integer MM (1M1001≤M≤100), which is the number of patches that Adam wishes to sew onto the quilt.

The next MM lines of input describe the placement and types of these patches. The jjth such line contains three integers q_jq\_j (1q_jR1≤q\_j≤R), t_jt\_j (1t_jC1≤t\_j≤C), and p_jp\_j (1p_jN1≤p\_j≤N). This means that the p_jp\_jth patch is sewn onto the quilt with its top-left corner on the q_j,t_jq\_j,t\_j row/column position of the quilt. This list is given in the order that they are sewn onto the quilt.

출력

Display the completed quilt. That is, display RR rows and CC columns of ASCII characters where each position is the pattern of the quilt after sewing on the given patches whilst removing excess fabric.