QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100

#19052. 搭骰子塔

Statistics

Sanghun 有 $N$ 個正方體骰子,依序稱為 $1$ 號、$2$ 號、$\ldots$、$N$ 號骰子。

每個骰子的每個面上都寫有一個 $1$ 到 $6$ 的整數。同一個骰子的不同面上的數字總是不同,且相對的兩個面上的數字之和總是 $7$。

Sanghun 想使用這 $N$ 個骰子搭骰子塔。具體過程如下。

  1. 將所有 $N$ 個骰子擲在地板上。

  2. 記錄每個骰子頂面的數字。從 $1$ 號到 $N$ 號骰子,依序記為 $A_1,A_2,\ldots,A_N$。

  3. 從地板上的骰子中選擇至少一個,在桌上搭一座新塔。可以將骰子從地板上拿起並移動,但不能改變骰子的朝向。所選骰子的堆疊順序可以任意安排,但必須全部垂直堆成一列。相互接觸的兩個面上的數字必須相同。

  4. 重複步驟 3,直到地板上沒有剩餘骰子。

例如,搭塔過程可以如下進行。

  1. Sanghun 在地板上擲出四個骰子,$1$ 號到 $4$ 號骰子的頂面數字分別為 $3,3,5,4$。

  2. Sanghun 從地板上選出 $1$、$2$、$4$ 號骰子,並依從下到上 $1$、$4$、$2$ 號的順序堆成塔。$1$ 號骰子的頂面和 $4$ 號骰子的底面都寫著 $3$,這兩個面相互接觸。同樣,$4$ 號骰子的頂面和 $2$ 號骰子的底面都寫著 $4$,這兩個面相互接觸。

  3. Sanghun 選出地板上剩餘的 $3$ 號骰子,搭成一座只有一個骰子的塔。

  4. 地板上已無剩餘骰子,搭塔結束。Sanghun 一共搭了兩座塔。

Sanghun 希望適當選擇堆疊方法,使搭成的塔數最少。給定擲出 $N$ 個骰子後各骰子的頂面數字,求最少能搭成多少座塔。

資料範圍

  • 所有輸入數均為整數。

  • $2\le N\le200\,000$。

  • 對每個滿足 $1\le i\le N$ 的整數 $i$,有 $1\le A_i\le6$。

子任務

1.(8 分)$N=2$。

2.(28 分)骰子頂面數字均為 $3$ 或 $4$。即對每個滿足 $1\le i\le N$ 的整數 $i$,有 $A_i=3$ 或 $A_i=4$。

3.(31 分)對於任意兩個不同的整數 $x,y$($1\le x,y\le6$),頂面寫著 $x$ 的骰子數量和頂面寫著 $y$ 的骰子數量不同。

4.(33 分)無額外限制。

輸入格式

第一行給出整數 $N$。

下一行依序給出 $N$ 個整數 $A_1,A_2,\ldots,A_N$,以空格分隔。

輸出格式

第一行輸出 Sanghun 透過適當選擇堆疊方法能搭成的最少塔數。

範例

輸入格式 1

4
3 3 5 4

輸出格式 1

2

輸入格式 2

2
3 4

輸出格式 2

1

輸入格式 3

5
1 1 6 1 1

輸出格式 3

3

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.