問題一覧 > 通常問題

No.265 Math Test

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 95
作問者 : btk
お気に入りにしたユーザー ProblemId : 605 / 自分の提出
問題文最終更新日: 2026-06-25 04:12:45
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 117 (順位表) の他の問題:

Problem Statement

Tanaka, a high school student, is taking a math test.
However, there is a problem he cannot solve, and at this rate he will get a failing grade.
That problem is to solve a single-variable polynomial containing derivatives.

Tanaka's brain is connected to the Internet, so even during the test he can send an expression to a computer and receive the answer.
For Tanaka's sake, write a program that calculates and solves the given expression.

The only operators appearing in the expression are '+', representing addition, and '*', representing multiplication.
The values appearing in the expression are constants, the variable 'x', and the derivative "d{$f(x)$}" of an expression $f(x)$.
(The derivative of $f(x)$ is $\frac{d}{dx}\{f(x)\}$ in the usual Leibniz notation, but it is written as "d{$f(x)$}" to simplify the expression.)

Note that because the operators are limited, the n-th power of $x$ is represented as a multiplication of n copies of $x$, as in $x^n=x*x*x*...*x*x$.
The operator precedence is '+' < '*', the same as in the real world.

(Addendum) It is generally known that $\frac{d}{dx}\{x^n\}=n*x^{n-1}$.
It is generally known that $\frac{d}{dx}\{x^n +\frac{d}{dx}{x^n}\}=\frac{d}{dx}\{x^n\}+\frac{d^2}{dx^2}\{x^n\}= n*x^{n-1}+n*(n-1)*x^{n-2}$ (linearity).

Input

$N$
$d$
$S$

$N$ represents the number of characters in the string $S$ representing the expression.
$d$ represents the maximum degree of the variable x appearing in the expression (before differentiation).
$S$ is a string of length $N$ representing the expression. $S$ contains no spaces.

$1 \le N=|S| \le 50000$
$0 \le d \le 10$

The expression $S$ contains the operators '+' and '*', constants, the variable 'x', and derivatives "d{$T$}". $T$ is also a string representing an expression, and $1\le|T|$ is guaranteed.
Also, each constant appearing in the expression is an integer between 1 and 9, inclusive.

No single term contains two or more constants.
That is, there is no input containing a term in which constants appear two or more times, such as "2*2*x".
The constant is not necessarily at the beginning of a term, as in "x*2".

The only operator that can be adjacent to a derivative is '+'.
That is, there is no input such as "x*d{x}"

Output

$A_{0} \: A_{1} \: A_{2} \: ... \: A_{d-1} \: A_{d}$

Find the result $A_{0}*x^{0}+A_{1}*x^{1}+...+A_{d}*x^{d}$ of calculating all the derivatives contained in the expression.
Output the coefficients $A_{0},A_{1},A_{2},... ,A_{d-1},A_{d}$ of $x_{0},x_{1},x_{2},... ,x_{d-1},x_{d}$.
Be careful about the values of the coefficients in the result.
Print a newline at the end.

Sample

Sample 1
Input
8
2
d{x*x+x}
Output
1 2 0

Since $\frac{d}{dx}\{x^2+x\}=2x+1$, the coefficient of $x^0$ (that is, the constant) is 1, the coefficient of $x^1$ is 2, and the coefficient of $x^2$ is 0.

Sample 2
Input
19
3
d{2*x+d{3*x*x*x}}+x
Output
2 19 0 0

An expression being differentiated may itself contain derivatives.

Sample 3
Input
1
1
x
Output
0 1

The input may also be a monomial with no operators.

Sample 4
Input
59
3
x*x*x+d{x*x*x}+d{d{x*x*x}}+d{d{d{x*x*x}}}+d{d{d{d{x*x*x}}}}
Output
6 6 3 1

I hate math

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。