QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 512 MB 總分: 100

#10200. 腐败

统计

小 Mirko 被电视上那个人的演讲迷住了。他确信自己理解了其中的信息:他必须篡改二进制数字的位。

Mirko 考虑数字 $0, 1, \dots, 2^N - 1$(视为具有 $N$ 个二进制位的二进制数)。出于对篡改的渴望,Mirko 将选择两个恰好有一位不同的数字 $X$ 和 $Y$ ($0 \le X, Y < 2^N$)。然后,他会将这两个数字中该位上的符号覆盖为“?”,从而实现篡改:数字 $X$ 和 $Y$ 将无法再被区分。Mirko 将对剩余的数字重复此过程,直到他获得恰好 $2^{N-1}$ 对无法区分的数字。换句话说,每个 $0$ 到 $2^N - 1$ 之间的数字都恰好属于一对,且两个数字能组成一对的充要条件是它们恰好有一位不同。

作为一项额外的挑战,Mirko 决定他想要恰好 $a_i$ 对数字,其中被覆盖的“?”符号位于第 $i$ 位,对于每个 $i = 0, 1, \dots, N - 1$。这里,位从最低有效位到最高有效位编号,因此第 $i$ 位对应的值为 $2^i$。请帮助 Mirko 选择这些数对以满足所需条件,或者确定这是不可能的。

输入格式

第一行包含一个正整数 $N$。

第二行包含 $N$ 个非负整数 $a_i$($i = 0, \dots, N - 1$),其中 $a_i$ 表示在第 $i$ 位上不同的数对所需数量。所有 $a_i$ 的总和恰好为 $2^{N-1}$。

输出格式

如果无法形成满足所需条件的数对,输出一行包含 $-1$。

否则,输出 $2^{N-1}$ 行。每行应包含两个空格分隔的整数 $X$ 和 $Y$,表示选定的一对。你可以以任何顺序输出这些数对。

如果存在多个解,输出任意一个即可。

子任务

在所有子任务中,均满足 $1 \le N \le 20$。

在每个子任务中,20% 的分数奖励给仅确定是否可能满足条件。对于这些分数,如果你输出的不是 $-1$,你可以打印任何一种配对方式(即使它没有完全满足所需条件)。

子任务 分数 数据范围
1 15 $N \le 4$
2 15 $N \ge 2$ 且对于所有 $i > 2$,$a_i = 0$
3 20 $N \le 6$
4 50 无额外限制

样例

样例输入 1

2
2 0

样例输出 1

0 1
2 3

样例输入 2

2
1 1

样例输出 2

-1

样例输入 3

3
2 0 2

样例输出 3

0 1
2 6
3 7
4 5

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.