QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#15216. 2048

Statistics

Alice 正在玩一个类似于 2048 的游戏。

在这个游戏中,给定一个长度为 $n$ 的整数数组 $a_1, a_2 \dots a_n$。每个 $a_i$ 都可以写成 2 的整数次幂。具体来说,$a_i = 2^{k_i}$。

Alice 可以进行一种称为合并(merge)的操作。在每次合并操作中,Alice 可以选择两个相邻且相等的数,然后将这两个数替换为它们的和。具体来说,Alice 可以选择一个满足 $a_i = a_{i+1}$ 的整数 $i$ ($1 \le i < n$),然后将 $a_i$ 的值修改为 $a_i + a_{i+1}$,并从数组中删除 $a_{i+1}$。

例如,对于数组 $[2, 4, 4, 8, 4]$,Alice 可以选择 $i = 2$ 进行一次合并。合并后,数组变为 $[2, 8, 8, 4]$。注意,在 Alice 通过合并获得一个长度为 $n - 1$ 的新数组后,她可以继续在新数组上进行合并,这意味着 Alice 可以进行多次(可能为零次)合并操作。

她想知道在所有可能得到的数组中,能获得的最大数是多少,以及为了得到包含该最大数的数组,她所需进行的最少操作次数。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 10^5$),表示给定数组的长度。

第二行包含 $n$ 个整数 $k_i$ ($1 \le i \le n, 1 \le k_i \le 100$),表示 $a_i = 2^{k_i}$。

输出格式

输出一行两个整数 $K, T$,用空格分隔,表示 Alice 可以获得的最大 2 的幂次(即最大数为 $2^K$)以及为了得到包含该数的数组所需进行的最少合并次数(如果 Alice 不需要任何操作,则 $T=0$)。

样例

输入样例 1

7
1 3 1 1 2 2 1

输出样例 1

4 3

输入样例 2

5
100 90 90 90 90

输出样例 2

100 0

说明

在第一个样例中,最大数为 $2^4$,且至少需要 3 次操作。可以通过以下操作获得:

  • 第一次合并:选择 $i = 3$,Alice 将获得新数组 $[2, 8, 4, 4, 4, 2]$。
  • 第二次合并:选择 $i = 3$,Alice 将获得新数组 $[2, 8, 8, 4, 2]$。
  • 第三次合并:选择 $i = 2$,Alice 将获得新数组 $[2, 16, 4, 2]$。

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.