QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 1024 MB Points totaux : 100

#3523. 把狗挡在外面

Statistiques

你最好的朋友一直在向你抱怨她邻居那些烦人的狗——显然,它们不断地在她的花园里搞破坏,还留下臭烘烘的“礼物”。今天,她决定开始着手解决这个问题:筑起一堵墙把它们挡在外面。

当然,这堵墙必须在所有地方保持相同的高度(即呈矩形),并且不能有任何会让狗钻过去的洞。不过,你的朋友并不太在意墙的具体尺寸。

她已经买好了她打算使用的石头(她想把它们全部用上!),并按大小进行了分类。所有石头的宽度相同,但长度和高度可能不同。然而,对于每一块石头,其长度等于其高度,且两者均为 2 的幂。墙的宽度必须等于石头的宽度,这意味着你不能旋转石头,也不能将两块石头前后放置。

给定石头的边长和数量,确定是否可以使用所有现有的石头筑起一堵墙,如果可以,这堵墙的长度和高度可能是多少。

图 K.1:第一个样例的示意图。

输入格式

输入包含: 一行包含一个整数 $n$ ($0 \le n \le 25$),表示最大的石头边长为 $2^n$。 一行包含 $n + 1$ 个整数 $m_0, \dots, m_n$ ($0 \le m_i \le 10^{15}$,对于每个 $i$,$m_n \ge 1$),其中 $m_i$ 描述了边长为 $2^i$ 的石头的数量。

保证所有石头的总面积不超过 $10^{15}$。

输出格式

如果可以筑起一堵没有洞的矩形墙,输出一行包含两个整数,即可以筑成的墙的长度和高度。否则,输出 impossible。如果存在多种解,输出其中任意一个。

样例

样例输入 1

2
2 1 3 3

样例输出 1

9 9

样例输入 2

2
0 3 2

样例输出 2

impossible

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.