CF550E.Brackets in Implications
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Implication is a function of two logical arguments, its value is false if and only if the value of the first argument is true and the value of the second argument is false.
Implication is written by using character '
', and the arguments and the result of the implication are written as '0' (false) and '1' (true). According to the definition of the implication:




When a logical expression contains multiple implications, then when there are no brackets, it will be calculated from left to fight. For example,
.
When there are brackets, we first calculate the expression in brackets. For example,
.
For the given logical expression
determine if it is possible to place there brackets so that the value of a logical expression is false. If it is possible, your task is to find such an arrangement of brackets.
蕴含(Implication)是一个具有两个逻辑参数的函数,当且仅当第一个参数的值为真(true)而第二个参数的值为假(false)时,其结果为假(false)。
蕴含用符号 '
' 表示,其参数与结果均以 '0'(假)和 '1'(真)表示。根据蕴含的定义:




当一个逻辑表达式包含多个蕴含运算符时,若无括号,则按从左到右的顺序依次计算。例如:

当存在括号时,则优先计算括号内的表达式。例如:

对于给定的逻辑表达式
,请判断是否可能通过添加括号,使得该逻辑表达式的值为假(false)。若可能,请找出这样一种加括号的方式。
输入格式
The first line contains integer n (1 ≤ n ≤ 100 000) — the number of arguments in a logical expression.
The second line contains n numbers _a_1, _a_2, ..., a__n (
), which means the values of arguments in the expression in the order they occur.
第一行包含一个整数 $ n ( 1 \leq n \leq 100,000 $)——表示逻辑表达式中参数的个数。
第二行包含 $ n $ 个数 $ a_1,,a_2,,\dots,,a_n $(
),表示表达式中各参数按出现顺序所取的值。
输出格式
Print "NO" (without the quotes), if it is impossible to place brackets in the expression so that its value was equal to 0.
Otherwise, print "YES" in the first line and the logical expression with the required arrangement of brackets in the second line.
The expression should only contain characters '0', '1', '-' (character with ASCII code 45), '>' (character with ASCII code 62), '(' and ')'. Characters '-' and '>' can occur in an expression only paired like that: ("->") and represent implication. The total number of logical arguments (i.e. digits '0' and '1') in the expression must be equal to n. The order in which the digits follow in the expression from left to right must coincide with _a_1, _a_2, ..., a__n.
The expression should be correct. More formally, a correct expression is determined as follows:
- Expressions "0", "1" (without the quotes) are correct.
- If _v_1, _v_2 are correct, then _v_1->_v_2 is a correct expression.
- If v is a correct expression, then (v) is a correct expression.
The total number of characters in the resulting expression mustn't exceed 106.
If there are multiple possible answers, you are allowed to print any of them.
如果无法在表达式中添加括号使得其值等于 0,则输出 "NO"(不带引号)。
否则,第一行输出 "YES",第二行输出满足要求的、添加了括号的逻辑表达式。
该表达式只能包含字符 '0'、'1'、'-'(ASCII 码为 45 的字符)、'>'(ASCII 码为 62 的字符)、'(' 和 ')'。字符 '-' 和 '>' 在表达式中仅能成对出现,即形如 "->",并表示逻辑蕴含(implication)。表达式中逻辑操作数(即数字 '0' 和 '1')的总数必须恰好为 n,且这些数字从左到右的顺序必须与 a1,a2,…,an 完全一致。
该表达式必须是合法的。更形式化地,合法表达式定义如下:
- 字符串
"0"、"1"(不带引号)是合法表达式; - 若 v1、v2 是合法表达式,则 v_1\text{->}v_2 是合法表达式;
- 若 v 是合法表达式,则 (v) 是合法表达式。
最终表达式的总字符数不得超过 106。
若存在多个可能的答案,输出任意一个即可。
输入输出样例
输入#1
4 0 1 1 0
输出#1
YES (((0)->1)->(1->0))
输入#2
2 1 1
输出#2
NO
输入#3
1 0
输出#3
YES 0
输入解题思路,AI测评打分。不知道怎么写?