Drawing Lines

시간 제한2초메모리 제한2048 MB

요약
좌표가 모두 다른 N개의 점이 각각 수직 또는 수평 방향을 가질 때, 광선들이 서로 만나지 않도록 방향을 정하는 경우의 수를 구한다.
난이도

어려움10점 중 8점

유형
조합론, 정렬, 그래프
정답자
아직 제출이 없습니다

문제

Busy Beaver likes to draw lines on paper. However, he gets sad when two lines intersect. One night, he dreamed of a masterpiece drawing consisting of many rays with no intersections. But, when he woke up, he only remembered where the rays started, and not which direction they went in! Help him recreate the drawing.

Formally, you are given NN points on the plane, each with distinct integer xx and yy coordinates in the range \[1,N]\[1, N]. Each point is labeled with either \tt{UD} or \tt{LR}. For each \tt{UD} point, you must draw an infinitely long ray starting at that point that goes vertically either up or down. Likewise, for each \tt{LR} point, you must draw an infinitely long ray starting at that point that goes horizontally either left or right.

Out of all 2N2^N ways to assign directions to each point, figure out whether there is an assignment where no two rays intersect, and if one exists, output the number of satisfying assignments, modulo 109+710^9 + 7.

For your convenience, we promise that if xx is the number of satisfying assignments and x>0x > 0, then x≢0(mod109+7)x \not \equiv 0 \pmod{10^9+7}.

입력

Each test contains multiple test cases. The first line of input contains a single integer TT (1≤T≤104)(1 \leq T \leq 10^4), the number of test cases.

The first line of each test case contains a positive integer NN (1≤N≤103)1 \le N \le 10^3), representing the number of points.

The ii-th of the next NN lines contain two integers x_i,y_ix\_i, y\_i and a string s_is\_i, where (x_i,y_i)(x\_i, y\_i) denotes the location of the ii-th point, and s_i∈UD,LRs\_i \in \\{\tt{UD}, \tt{LR}\\} denotes the allowed ray directions from the point.

x_ix\_i are guaranteed to be pairwise distinct integers in the range \[1,N]\[1, N], and the same holds for y_iy\_i.

You are guaranteed that the sum of NN over all test cases is at most 10410^4.

출력

For each of the TT test cases, output two lines.

On the first line, output "YES" or "NO", representing whether a satisfying assignment exists. You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

On the second line, output the number of satisfying assignments, modulo 109+710^9+7.

힌트

In the first test case, any of the 22=42^2 = 4 assignments results in no intersections.

In the second test case, if the first point is assigned D and the second point is assigned L, there is an intersection of the two rays at (1,1)(1, 1). All 33 other assignments work.

In the third test case, all assignments result in at least one intersection.

The second test case is depicted below.

예제1

  1. 예제 1

    입력
    3
    2
    1 1 UD
    2 2 UD
    2
    1 2 UD
    2 1 LR
    7
    1 5 UD
    2 3 UD
    3 4 LR
    4 1 LR
    5 7 LR
    6 2 UD
    7 6 UD
    
    예상 출력
    YES
    4
    YES
    3
    NO
    0