QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#10283. A 01 string, n ternary operators, the final value is 1

统计

The ternary operator expression $a?b:c$ means that if $a$ is true, it returns $b$, otherwise it returns $c$. The ternary operator is right-associative: $a?b:c?d:e$ is equivalent to $a?b:(c?d:e)$. If you do not remember the order of operations, you can always use parentheses. $0$ is false, $1$ is true.

Given a $01$ string of length $2n + 1$, you need to use the ternary operator $n$ times, i.e., by inserting exactly $n$ question marks $?$ and $n$ colons $:$ as well as some parentheses into the string, such that the result of the expression is $1$, or determine that it is impossible.

Input

Read data from standard input. The first line contains a positive integer $n$ ($1 \le n \le 1.5 \times 10^5$). The second line contains a $01$ string of length $2n + 1$, representing the given string.

Output

Output to standard output. If there is no solution, output a single line containing No. If there is a solution, output Yes on the first line, and an expression that evaluates to $1$ on the second line. You may use parentheses, but you must ensure that the order of the digits in your expression is the same as in the original string. You must ensure that the length of the expression you output does not exceed $10n + 1000$. It can be proven that if a solution exists, there must exist a construction that satisfies the conditions.

Examples

Input 1

2
10101

Output 1

Yes
(1?0:1)?0:1

Note 1

If you output an expression like (((1?0:((((1)))))?0:1)), it is also considered correct.

Input 2

2
00000

Output 2

No

Note

You can directly use g++ to compile your expression to check its value, but this method cannot check whether the order of the digits is consistent, nor can it check whether the number of times you use the ternary operator is exactly $n$, i.e., whether there is a $?$ or $:$ between every two adjacent digits:

#include <cassert>
#define YOUR_EXPRESSION <your_expression>
int main(){
    assert(YOUR_EXPRESSION);
    return 0;
}

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.