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

31683번 - Zlagalica 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB37222165.625%

문제

Little Maja has always loved puzzles. And since everyone knew that for a long time now, it is no wonder that one sunny day, Maja received an odd puzzle as a gift..

This puzzle has $n$ pieces. Each piece has rectangular shape and is of a certain color. Also, each piece has 2ドル$ numbers written on its back: $u$ and $d$. After a period of skillfully combining pieces and trying to fit them together, Maja figured out the meaning of those numbers.

She found out that number $u$ represents "direction", in other words, does the next piece of the puzzle connect with the current one from the upper or from the right side of the current piece. Number $d$ specifies the starting column/row where we connect the next piece of the puzzle with current one. In more detail:

  • If $u$ is equal to 0ドル,ドル we add next piece above the current one by connecting its bottom left corner with current piece’s top edge at column d.
  • If $u$ is equal to 1ドル,ドル we add next piece to the right by connecting its bottom left corner with current piece’s right edge at row d.

Let’s demonstrate this for pieces colored in colors "a" and "b". Picture 1 shows the case where $u = 0,ドル and $d = 3$. Picture 2 shows case when $u = 1$ and $d = 3$. (In both cases, numbers $u$ and $d$ represent numbers written on the back of piece colored "a").

. . b b b b b
. . b b b b b
a a a a . . .
a a a a . . .
a a a a . . .
a a a a . . . . .
a a a a b b b b b
a a a a b b b b b
Picture 1 Picture 2

Maja has grown tired of this puzzling puzzle, but her curiosity knows no bounds! That’s why she’s asking for your help. She’s interested in knowing, for a given description of every piece of the puzzle and the sequence of their placement, what will the completed puzzle look like? Write a program that prints the dimensions (height and width) of the completed puzzle, as well as its final appearance within a rectangle of the same height and width, where "." represents places where there is no part of the puzzle.

입력

In first row, there is $n$ (1ドル ≤ n ≤ 20$), number of puzzle pieces.

In the $i$-th of next $n$ rows there are per 1ドル$ character and 4ドル$ integers, in order: $b_i,ドル $r_i,ドル $s_i,ドル $u_i,ドル $d_i$ - description of $i$-th piece:

  • $b_i$ will always be 1ドル$ lowercase letter of english alphabet, and it represents the color of the $i$-th puzzle piece
  • $r_i$ and $s_i$ (1ドル ≤ r_i , s_i ≤ 10$) represent in order, number of rows and columns of $i$-th puzzle piece
  • $u_i$ and $d_i$ (0ドル ≤ u_i ≤ 1,ドル 1ドル ≤ d_i ≤ r_i , s_i$ (depends on $u_i$)) are numbers on the back of $i$-th puzzle piece, same as in the task statement.

In the last row of input there are $n$ integers, order in which pieces are connected, where number $i$ (1ドル ≤ i ≤ n$) represents $i$-th puzzle piece in input. Each puzzle piece will appear in the sequence exactly once.

출력

Print the height and width of the completed puzzle. After that, print the appearance of the puzzle within a rectangle of the same height and width. In the places within the rectangle where there is no part of the puzzle, print ".".

제한

서브태스크

번호배점제한
117

The order of connecting the puzzle pieces will be identical to the order of inputting them.

212

For each puzzle piece: $u = 0$.

312

For each puzzle piece: $u = 1$.

49

No additional constraints.

예제 입력 1

2
a 3 4 0 3
b 2 5 1 1
1 2

예제 출력 1

5 7
..bbbbb
..bbbbb
aaaa...
aaaa...
aaaa...

예제 입력 2

2
a 3 4 0 3
b 2 5 1 1
2 1

예제 출력 2

4 9
.....aaaa
.....aaaa
bbbbbaaaa
bbbbb....

예제 입력 3

4
g 9 5 0 2
a 3 2 1 1
c 5 10 0 2
p 8 7 1 6
4 3 2 1

예제 출력 3

18 17
..........ggggg..
..........ggggg..
..........ggggg..
..........ggggg..
..........ggggg..
..........ggggg..
..........ggggg..
..........ggggg..
........aaggggg..
........aa.......
ppppppp.aa.......
pppppppcccccccccc
pppppppcccccccccc
pppppppcccccccccc
pppppppcccccccccc
pppppppcccccccccc
ppppppp..........
ppppppp..........

힌트

출처

Contest > Croatian Open Competition in Informatics > COCI 2023/2024 > Contest #5 1번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

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

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