QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#22719. 짚단 입체

Statistics

소는 $N$ ($1 \le N \le 25{,}000$)개 $1\times1\times1$ 정육면체 짚단으로 모양을 만든다.

1은 바닥, 2부터 $N$ 순서로 이미 둔 짚단 상대 위치에 붙인다. 예:

1 바닥.

2는 1 오른쪽.

3은 2 앞.

4는 3 앞.

뒤집은 L 모양:

                     +--+--+

                1-> /  /  /| <-2

                   +--+--+ +

                   | /  /|/

                   ++--+ +

                   /  /|/ <-3

                  +--+ +

                  |  |/ <-4

                  +--+

추가 짚단:

5는 1 위.

높이를 더한다:

                     +--+

                    /  /|

                   +--+ +--+

               5-> |  |/  /| <-2

                   +--+--+ +

               1-> | /  /|/

                   ++--+ +

                   /  /|/ <-3

                  +--+ +

                  |  |/ <-4

                  +--+

그러나 또 명령:

6은 4 뒤.

3과 6 겹쳐 무효다.

$N$개와 배치가 주어지면 유효할 때 노출 표면적. 노출 면은 다른 짚단 어떤 면도 바닥도 안 닿는다(바닥 위 큐브 밑면 아님). 무효면 $-1$. 첫째에서 25짚단 너비보다 멀리 없고 바닥 아래도 없다.

입력

  • 1번째 줄: 정수 $N$.

  • $2..N$번째 줄: j X로 $2..N$ 배치, 2번째 줄 2, 3번째 줄 3 등. X: L 왼쪽, R 오른쪽, F 앞, B 뒤, O 위, U 아래. 접착할 수 있어 빈 공간 위도 밑 지지 불필요.

출력

  • 1번째 줄: 노출 표면적 또는 무효 -1.

예제

입력 1

5
1 R
2 F
3 F
1 O

출력 1

18

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.