CF1132A.Regular Bracket Sequence

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular if it 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 22. So, overall you have cnt1cnt_1 strings "((", cnt2cnt_2 strings "()", cnt3cnt_3 strings ")(" and cnt4cnt_4 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)2(cnt_1 + cnt_2 + cnt_3 + cnt_4). 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.

如果一个字符串仅由字符 "(" 和 ")" 组成,则称其为括号序列。若可以通过向该序列中插入字符 "+" 和 "1" 得到一个合法的算术表达式,则称该括号序列为正则括号序列(regular bracket sequence)。例如,""(空串)、"(())" 和 "()()" 是正则括号序列;"))" 和 ")(( 是括号序列(但不是正则括号序列);而 "(a)" 和 "(1)+(1)" 则根本不是括号序列。

你拥有一些字符串,每个字符串均为长度为 22 的括号序列。具体而言,你有 cnt1cnt_1 个字符串 "((",cnt2cnt_2 个字符串 "()",cnt3cnt_3 个字符串 ")(",以及 cnt4cnt_4 个字符串 "))"。你想将这些字符串以某种顺序依次拼接起来,从而得到一个总长度为 2(cnt1+cnt2+cnt3+cnt4)2(cnt_1 + cnt_2 + cnt_3 + cnt_4) 的长括号序列。现在你想知道:是否存在一种拼接顺序,使得最终得到的括号序列是正则括号序列?注意:你不可以删除任何字符或字符串,也不可以添加任何内容。

输入格式

The input consists of four lines, ii-th of them contains one integer cnticnt_i (0≤cnti≤1090 \le cnt_i \le 10^9).

输入包含四行,第 ii 行包含一个整数 cnticnt_i(0≤cnti≤1090 \le cnt_i \le 10^9)。

输出格式

Print one integer: 11 if it is possible to form a regular bracket sequence by choosing the correct order of the given strings, 00 otherwise.

输出一个整数:如果可以通过选择给定字符串的正确顺序来构成一个合法括号序列,则输出 11,否则输出 00。

输入输出样例

  • 输入#1

    3
    1
    4
    3

    输出#1

    1
  • 输入#2

    0
    0
    0
    0

    输出#2

    1
  • 输入#3

    1
    2
    3
    4

    输出#3

    0

说明/提示

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.

在第一个例子中,可以构造字符串 "(())()(()((()()()())))",它是一个合法的括号序列。

在第二个例子中,可以构造字符串 "",它是一个合法的括号序列。

输入解题思路,AI测评打分。不知道怎么写?

首页