QOJ.ac

QOJ

시간 제한: 1 s 메모리 제한: 512 MB 총점: 100

#4400. 家庭作业

통계

小海伦娜刚读完小学一年级。她是一名模范学生,成绩全优,并且对数学有着极大的热情。她目前正与家人享受着应得的假期,但她开始想念她的日常数学作业了。幸运的是,她的哥哥决定满足她对知识的渴望,给她出了下面这道题。

有效表达式的递归定义如下: 字符串 ? 是一个代表数字的有效表达式。 如果 $A$ 和 $B$ 是有效表达式,那么 $\min(A,B)$ 和 $\max(A,B)$ 也是有效表达式,其中前者表示返回两个参数中较小值的函数,后者表示返回两个参数中较大值的函数。

例如,根据上述定义,表达式 $\min(\min(?,?),\min(?,?))$ 和 $\max(?,\max(?,\min(?,?)))$ 是有效的,但表达式 ??、$\max(\min(?))$ 和 $\min(?,?,?)$ 是无效的。

海伦娜得到了一个包含总共 $N$ 个问号的有效表达式。每个问号都要用集合 $\{1, 2, \dots, N\}$ 中的一个数字来替换,使得该集合中的每个数字在表达式中恰好出现一次。换句话说,问号被 $1$ 到 $N$ 的一个排列所替换。

一旦问号被数字替换,该表达式就可以被求值,其结果将是一个介于 $1$ 和 $N$ 之间的整数。考虑所有分配数字给问号的方式,海伦娜在对表达式求值后能得到多少种不同的值?

输入格式

第一行且仅包含一行,为一个有效的表达式。

输出格式

输出一个介于 $1$ 和 $N$ 之间的整数,表示通过对表达式求值所能得到的不同值的数量。

子任务

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

子任务 分值 数据范围
1 10 $N \le 9$
2 13 $N \le 16$
3 13 表达式中的每个函数至少有一个问号作为参数。
4 30 $N \le 1000$
5 34 无附加限制。

样例

输入 1

min(min(?,?),min(?,?))

输出 1

1

说明 1

无论数字如何分配,所得表达式的值总是等于集合 $\{1, 2, 3, 4\}$ 的最小值,即 $1$。因此,只有一种可能的值。

输入 2

max(?,max(?,min(?,?)))

输出 2

2

说明 2

数字 $3$ 和 $4$ 可以通过以下方式得到:$4=\max(4,\max(3,\min(2,1)))$ 和 $3=\max(3,\max(2,\min(1,4)))$。可以证明值 $1$ 和 $2$ 是无法得到的,因此答案为 $2$。

输入 3

min(max(?,?),min(?,max(?,?)))

输出 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.