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

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

Hexagonal Tiling

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

요약
변 길이가 N인 정육각형을 단위 마름모로 빈틈없이 채우되, 놓을 수 있는 각 마름모 위치마다 비용이 주어질 때 전체 비용의 최솟값을 구한다.
난이도

보통10점 중 7점

유형
그래프, 최소 신장 트리
정답자
아직 제출이 없습니다

문제

You are given a regular hexagon having sides of length NN. A regular hexagon can be split into unit equilateral triangles of side length 11 as shown in the figure below. We are going to completely fill the hexagon with unit rhombuses of side length 11 formed by joining two equilateral triangles which share an edge.

Hexagon formed from triangles

For each position a unit rhombus can be placed, the cost of placing a rhombus is given. Find the minimum cost required to fill the hexagon.

입력

The first line of input contains NN.

The following 2N2N lines contain the cost for a rhombus placed in each respective row.

Let’s say the cost of a rhombus formed by joining the jj-th and j+1j+1-th triangles of the ii-th row is p_i,jp\_{i,j}.

The ii-th of the 2N2N lines of input contains p_i,1,p_i,2,…p\_{i,1},p\_{i,2},\ldots.

The next 2N−12N-1 lines of input contain the cost for a rhombus placed across two rows.

Let’s say the cost of a rhombus formed by joining the jj-th inverted triangle of the ii-th row and the triangle above it is q_i,jq\_{i,j}.

The ii-th of the 2N−12N-1 lines contains q_i+1,1,q_i+1,2,…q\_{i+1,1},q\_{i+1,2},\ldots.

출력

Print the minimum cost required to fill the hexagon using unit rhombuses. It can be proved that it is always possible to fill a hexagon using unit rhombuses.

제한

  • 1≤N≤1001\leq N\leq 100
  • 0≤p_i,j,q_i,j≤1090\leq p\_{i,j},q\_{i,j}\leq 10^9

힌트

The costs of rhombuses given in example 1

The solution for example 2

예제2

  1. 예제 1

    입력
    1
    2 3
    4 5
    1 6
    
    예상 출력
    9
    
  2. 예제 2

    입력
    2
    3 14 15 9
    2 6 5 3 5 8
    97 9 3 2 3 8
    4 6 26 4
    3 3 8
    3 2 7 9
    5 0 2
    
    예상 출력
    58