CF1860F.Evaluate RBS

省选/NOI-

通过率:0%

时间限制:10.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given 2n2n tuples of values (a,b,c)(a, b, c), where aa and bb are positive integers and cc is a bracket '(' or ')'. Exactly nn tuples have $c = $'(' and the other nn tuples have c=c = ')'.

You are asked to choose two positive values xx and yy (x>0x \gt 0 and y>0y \gt 0; not necessarily integers) and sort the tuples in the increasing value of a⋅x+b⋅ya \cdot x + b \cdot y. If several tuples have the same value, you can place them in any order among themselves.

Is it possible to choose such xx and yy that taking brackets cc from the tuples in the resulting order produces a regular bracket sequence?

A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence.

给你 2n2n 个三元组 (a,b,c)(a, b, c),其中 aa 和 bb 是正整数,cc 是左括号 '(' 或右括号 ')'。恰好有 nn 个三元组满足 $c = $ '(',其余 nn 个三元组满足 $c = $ ')'。

你需要选择两个正实数 xx 和 yy(即 x>0x \gt 0 且 y>0y \gt 0;不一定是整数),并按照 a⋅x+b⋅ya \cdot x + b \cdot y 的值升序对这些三元组进行排序。若若干三元组的 a⋅x+b⋅ya \cdot x + b \cdot y 值相等,则它们之间的相对顺序可任意安排。

是否存在这样的 xx 和 yy,使得按上述排序后依次取出各三元组中的括号 cc,所构成的括号序列是一个合法括号序列(regular bracket sequence)?

一个合法括号序列是指:通过在该序列的原始字符之间插入字符 "1" 和 "+",可将其转化为一个正确的算术表达式。

输入格式

The first line contains a single integer tt (1≤t≤15001 \le t \le 1500) — the number of testcases.

The first line of each testcase contains a single integer nn (1≤n≤15001 \le n \le 1500).

The ii-th of the next 2n2n lines contains two integers aia_i and bib_i (1≤ai,bi≤1061 \le a_i, b_i \le 10^6) and a character cic_i ($c_i = $'(' or $c_i = $')'). Exactly nn tuples have $c_i = $'(' and the other nn tuples have ci=c_i = ')'.

The sum of nn over all testcases doesn't exceed 15001500.

第一行包含一个整数 tt(1≤t≤15001 \le t \le 1500)—— 表示测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤15001 \le n \le 1500)。

接下来的 2n2n 行中,第 ii 行包含两个整数 aia_i 和 bib_i(1≤ai,bi≤1061 \le a_i, b_i \le 10^6)以及一个字符 cic_i($c_i = $'(' 或 $c_i = $')')。其中恰好有 nn 个元组满足 $c_i = $'(',其余 nn 个元组满足 $c_i = $')'。

所有测试用例的 nn 值之和不超过 15001500。

输出格式

For each testcase, print "YES" if it's possible to choose such xx and yy that taking brackets cc from the tuples in the resulting order produces a regular bracket sequence. Otherwise, print "NO".

对于每个测试用例,如果存在满足条件的 xx 和 yy,使得按最终顺序从元组中取出括号 cc 能构成一个合法括号序列,则输出 "YES";否则输出 "NO"。

输入输出样例

  • 输入#1

    4
    1
    1 4 (
    2 3 )
    1
    1 2 )
    3 4 (
    4
    16 5 (
    12 3 (
    19 6 )
    4 10 )
    3 10 )
    19 11 (
    19 7 )
    7 14 (
    4
    16 8 (
    11 9 )
    20 10 )
    20 19 )
    2 13 (
    18 7 (
    15 19 )
    5 6 (

    输出#1

    YES
    NO
    NO
    YES

说明/提示

In the first testcase, you can choose x=10,y=0.1x = 10, y = 0.1. The values for tuples will be 10⋅1+0.1⋅4=10.410 \cdot 1 + 0.1 \cdot 4 = 10.4 and 10⋅2+0.1⋅3=20.310 \cdot 2 + 0.1 \cdot 3 = 20.3. Thus, the first tuple will go first, then the second one, making the bracket sequence "()", which is regular.

In the second testcase, you can't choose positive xx and yy such that the opening brackets gets assigned a value less or equal to the value of the closing bracket.

In the fourth testcase, you can choose x=0.6,y=0.55x = 0.6, y = 0.55. The bracket sequence is "(()(()))".

在第一个测试用例中,你可以选择 x=10,y=0.1x = 10, y = 0.1。两个元组的值分别为 10⋅1+0.1⋅4=10.410 \cdot 1 + 0.1 \cdot 4 = 10.4 和 10⋅2+0.1⋅3=20.310 \cdot 2 + 0.1 \cdot 3 = 20.3。因此,第一个元组排在前面,第二个元组排在后面,得到括号序列 "()",该序列是合法的(regular)。

在第二个测试用例中,你无法选择正数 xx 和 yy,使得左括号所对应的值小于或等于右括号所对应的值。

在第四个测试用例中,你可以选择 x=0.6,y=0.55x = 0.6, y = 0.55。括号序列为 "(()(()))"。

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

首页