問題一覧 > 通常問題

No.3143 Colorless Green Parentheses Sleep Furiously

レベル : / AI推定難易度 : 1450 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 63
作問者 : nauclhlt / テスター : 👑 p-adic
お気に入りにしたユーザー ProblemId : 12066 / 自分の提出
問題文最終更新日: 2025-05-11 23:50:17
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 467 (順位表) の他の問題:

Story

  1. ((()))
  2. )()()(

It is reasonable to assume that neither parenthesis sequence (1) nor (2) has ever appeared in a formula representing $1$. However, while (1) does not appear in formulas, it is correct, whereas (2) is not correct.

Problem Statement

A string obtained by concatenating one or more (any number of) copies of +1 to 1 is called a simple addition.

A string $X$ satisfying one of the following is called an expression:

  • $X$ is 1
  • $X$ is not 1, and $X$ becomes a simple addition after repeating the following operation as many times as possible: "Take a simple addition $Y$ contained in $X$ as a substring such that it forms ( $Y$ ), and replace that part with 1."

Examples of expressions: (1+1)+(1+1), ((1+1)+1)+1
Examples of strings that are not expressions: (1), ((1+1))+1

For an expression $T$, let $f(T)$ be its value when evaluated as a mathematical formula. For example, $f($1+(1+1)$)=3$ and $f($1+((1+1)+1)$)=4$.

Let $g(T)$ be the string obtained by deleting all characters other than ( and ) from $T$ and concatenating the remaining characters while preserving their order. For example, $g($1+(1+1)$)=$() and $g($1+((1+1)+1)$)=$(()).

You are given positive integers $N, K$ and a string $S$ of length $N$ consisting of ( and ).
Determine whether there exists an expression $E$ satisfying $f(E)=K$ and $g(E)=S$. If one exists, output one such expression.

Input

$N\ K$
$S$
  • $1\leq N\leq 10^5$
  • $1\leq K\leq 10^5$
  • $S$ is a string of length $N$ consisting of ( and )

Output

If there exists an expression $E$ satisfying the conditions, print Yes on the first line; otherwise, print No.
If the answer is Yes, then print one such $E$ on the second line. If the answer is No, print only one line.

Print a newline at the end.

Sample

Sample 1
Input
6 5
()(())
Output
Yes
(1+1)+(1+(1+1))

$f($(1+1)+(1+(1+1))$)=5$ and $g($(1+1)+(1+(1+1))$)=$()(()), so (1+1)+(1+(1+1)) indeed satisfies the conditions.

You may also output (1+1)+((1+1)+1).

Sample 2
Input
4 2
()()
Output
No

No expression $E$ satisfying the conditions exists.

Sample 3
Input
8 9
()()()()
Output
Yes
(1+1)+(1+1)+(1+1)+(1+1)+1

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