QOJ.ac

QOJ

时间限制: 2 s 内存限制: 256 MB 总分: 100

#4756. 多项式

统计

黑板左侧有 $N$ 个多项式,右侧有 $M$ 个多项式。你的任务是构造右侧黑板上的每一个多项式,并使操作次数最少。

要构造右侧的一个多项式,首先从左侧的 $N$ 个多项式中任选一个。可以对选定的多项式进行以下变换:

  • 微分:将多项式替换为其导数。
  • 积分:将多项式替换为其不定积分,并加上一个任意的积分常数。

变换可以以任意顺序进行任意次数,但每一次变换计为一次操作。如果右侧的多项式与左侧的某个多项式相同,则无需进行任何变换。

输入格式

输入文件的第一行包含两个整数:$N$ 和 $M$ ($1 \le N, M \le 10^5$)。

接下来的 $N + M$ 行描述了这些多项式,每行一个。前 $N$ 个多项式是黑板左侧的多项式,其余的是黑板右侧的多项式。

多项式 $a_0 + a_1x + \dots + a_Kx^K$ 的描述以一个非负整数 $K$(其次数)开始。接下来是整数 $a_0, a_1, \dots, a_K$,即多项式的系数 ($-10^9 \le a_i \le 10^9$)。其中,$a_K \neq 0$。

保证左侧所有多项式的次数之和不超过 $10^5$。右侧多项式的情况相同。

输出格式

对于右侧的每一个多项式,输出构造它所需的最少操作次数。按输入文件中多项式的顺序,每行输出一个答案。

样例

样例输入 1

2 1
2 1 1 1
2 7 6 2
2 7 6 1

样例输出 1

4

样例输入 2

2 1
2 1 1 1
0 1
1 1 1

样例输出 2

1

说明

在第二个样例中,黑板左侧有两个多项式:$p_1(x) = 1 + x + x^2$ 和 $p_2(x) = 7 + 6x + 2x^2$。我们需要得到多项式 $q(x) = 7 + 6x + x^2$。为此,我们先对 $p_1$ 进行两次微分,得到 $p_1'(x) = 1 + 2x$ 以及 $p_1''(x) = 2$。现在,我们将 $p_1''(x)$ 积分,取积分常数为 $6$,得到 $6 + 2x$。再次对结果进行积分,取积分常数为 $7$,得到 $7 + 6x + x^2$。总共使用了 $4$ 次操作。

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.