time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output
A string is called bracket sequence if it does not contain any characters other than “(“ and “)”. A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters “+” and “1” into this sequence. For example, “”, “(())” and “()()” are regular bracket sequences; “))” and “)((“ are bracket sequences (but not regular ones), and “(a)” and “(1)+(1)” are not bracket sequences at all.
You have a number of strings; each string is a bracket sequence of length $2$. So, overall you have $cnt1$ strings “((“, $cnt2$ strings “()”, $cnt3$ strings “)(“ and $cnt4$ strings “))”. You want to write all these strings in some order, one after another; after that, you will get a long bracket sequence of length $2(cnt1+cnt2+cnt3+cnt4)$. You wonder: is it possible to choose some order of the strings you have such that you will get a regular bracket sequence? Note that you may not remove any characters or strings, and you may not add anything either.
Input
The input consists of four lines, $i$-th of them contains one integer $cnt_i$ $(0≤cnt_i≤10^9)$.
Output
Print one integer: $1$ if it is possible to form a regular bracket sequence by choosing the correct order of the given strings, $0$ otherwise.
Examples
input
1 | 3 |
output
1 | 1 |
input
1 | 0 |
output
1 | 1 |
input
1 | 1 |
output
1 | 0 |
Note
In the first example it is possible to construct a string “(())()(()((()()()())))”, which is a regular bracket sequence.
In the second example it is possible to construct a string “”, which is a regular bracket sequence.
Solve
你有四种括号,”((“,”()”,”)(“,”))”, 给出四种括号的数量, 问能否将这些括号以某种顺序连接起来, 使得每个左括号都有与之匹配的右括号。
观察可以发现:如果要完全匹配,()
是不会对结果产生影响的,然后可以推出一个关系式:$cnt1=2\times cnt3+cnt4,cnt4=2\times cnt3+cnt1$
即:当$cnt3\neq0,cnt1=cnt4\neq0$或$cnt3=0,cnt1=cnt2$时,才会完全匹配
Code
1 | /************************************************************************* |