아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Bale Figures

면접 대비

시간 제한1초메모리 제한1024 MB

요약
큐브 N개를 앞선 베일에 상대적인 위치로 하나씩 놓으면서 겹침이나 바닥 침범을 판정하고, 노출된 표면적 또는 -1을 출력한다.
난이도

보통10점 중 7점

유형
시뮬레이션, 해시맵, 구현, 기하
정답자
아직 제출이 없습니다

문제

Cows like to build shapes out of hay bales. Each new shape is constructed from N (1 ≤ N ≤ 25,000) 1 x 1 x 1 cubic bales.

Bale 1 lies on the floor. After placing it, each successive bale from 2 through N is attached to the shape by placing the new bale in the proper relative position to one of the bales already placed. For instance, imagine the following figure:

  • Bale 1 - on the floor
  • Bale 2 - RIGHT Bale 1 (to Bale 1's right)
  • Bale 3 - FRONT Bale 2 (in front of Bale 2)
  • Bale 4 - FRONT Bale 3

This results in an (inverted) L-shape:

                     +--+--+                      
                1-> /  /  /| <-2                      
                   +--+--+ +
                   | /  /|/                         
                   ++--+ +                       
                   /  /|/ <-3                     
                  +--+ +                          
                  |  |/ <-4                       
                  +--+                            

Adding another bale:

  • Bale 5 - OVER Bale 1

adds height to the shape:

                     +--+                            
                    /  /|                           
                   +--+ +--+                      
               5-> |  |/  /| <-2                      
                   +--+--+ +
               1-> | /  /|/                         
                   ++--+ +                       
                   /  /|/ <-3                     
                  +--+ +                          
                  |  |/ <-4                       
                  +--+                            

But adding another directive:

  • Bale 6 - BACK Bale 4

results in an invalid shape, since bales 3 and 6 would overlap.

Given N bales and placements described as above, output the exposed surface area of the solid figure if the shape is valid. A face is considered exposed if it is not touched by any face of any other bale and does not touch the floor (i.e., is not the bottom of a cube on the floor). Output -1 if the shape is invalid. No bale will be placed farther than 25 bale-widths from the first bale. No bale will be placed below the floor level.

입력

  • Line 1: A single integer, N
  • Lines 2..N: These lines describe the placement of bales 2..N in the form "j X". Line 2 describes bale 2; line 3 describes bale 3; and so on. The letter "X" is one of: "L" (left), "R" (right), "F" (front), "B" (back), "O" (over), or "U" (under). The bales can be glued and require no underlying support if extended over an empty space.

출력

  • Line 1: The exposed surface area of the resulting solid. If the solid is invalid, output "-1".

예제1

  1. 예제 1

    입력
    5
    1 R
    2 F
    3 F
    1 O
    
    예상 출력
    18