QOJ.ac

QOJ

Time Limit: 10 s Memory Limit: 256 MB Total points: 100

#23803. 一年级生

Statistics

题目描述

JOI 君是小学 $1$ 年级学生。JOI 君非常喜欢刚学到的加法和减法,每当看到一排数字时,他就会在最后 $2$ 个数字之间填入 =,并在其余相邻数字之间都填入 + 或 -,以此构造等式来玩耍。例如,由 8 3 2 4 8 7 2 4 0 8 8 可以构造出等式 8+3-2-4+8-7-2-4-0+8=8。

构造出等式后,JOI 君会通过计算来验证它是否是一个正确的等式。然而,JOI 君还不知道负数,也不会计算超过 $20$ 的数。因此,在正确的等式中,只有从左往右计算等号左边时,计算过程中出现的所有数都在 $0$ 以上 $20$ 以下的等式,才是 JOI 君能够验证的正确等式。例如,8+3-2-4-8-7+2+4+0+8=8 虽然是正确的等式,但由于计算途中出现的 8+3-2-4-8 是负数,JOI 君无法验证这个等式是否正确。

给定一列数字作为输入,请编写程序求出 JOI 君能够构造并验证的正确等式的个数。

输入格式

输入文件共 $2$ 行。第 $1$ 行包含一个整数 $N$($3 \le N \le 100$),表示排列的数字个数。第 $2$ 行包含 $N$ 个 $0$ 以上 $9$ 以下的整数,以空格分隔。

在给定的 $60\%$ 的输入数据中,JOI 君能够构造并验证的正确等式的个数不超过 $2^{31}-1$。此外,在所有给定的输入数据中,JOI 君能够构造并验证的正确等式的个数不超过 $2^{63}-1$。

输出格式

输出 $1$ 行一个整数,表示 JOI 君能够构造并验证的正确等式的个数。

样例

样例输入 1

11
8 3 2 4 8 7 2 4 0 8 8

样例输出 1

10

样例输入 2

40
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1

样例输出 2

7069052760

在样例输入 $1$ 中,JOI 君能够构造并验证以下 $10$ 个正确的等式:

  • 8+3-2-4+8-7-2-4-0+8=8
  • 8+3-2-4+8-7-2-4+0+8=8
  • 8+3+2+4-8-7+2-4-0+8=8
  • 8+3+2+4-8-7+2-4+0+8=8
  • 8+3+2-4+8-7+2+4-0-8=8
  • 8+3+2-4+8-7+2+4+0-8=8
  • 8-3+2+4-8+7+2+4-0-8=8
  • 8-3+2+4-8+7+2+4+0-8=8
  • 8-3+2-4+8+7+2-4-0-8=8
  • 8-3+2-4+8+7+2-4+0-8=8

因此输出 $10$。

在样例输入 $2$ 中,请注意答案超出了 $32$ 位有符号整数的范围。

($2015$ 年 $2$ 月 $21$ 日追记) 经用户指出,发现样例输入 $1$ 说明中的等式存在错误,现已修正。第 $5$ 个等式原为 8+3-2-4+8-7+2+4-0-8=8,现已修正为 8+3+2-4+8-7+2+4-0-8=8。此外,第 $6$ 个等式原为 8+3-2-4+8-7+2+4+0-8=8,现已修正为 8+3+2-4+8-7+2+4+0-8=8。

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.