Submission #61192725


Source Code Expand

Copy
import sys
"""import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')
sys.setrecursionlimit(10**7)"""
import bisect
n,m=map(int,input().split())
bx={}
by={}
wx={}
wy={}
for _ in range(m):
x,y,c=sys.stdin.readline().split()
x,y=int(x),int(y)
if c=="B":
if x in bx:
bx[x]=max(bx[x],y)
else:
bx[x]=y
if y in by:
by[y]=max(by[y],x)
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
import sys
"""import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')
sys.setrecursionlimit(10**7)"""
import bisect

n,m=map(int,input().split())
bx={}
by={}
wx={}
wy={}
for _ in range(m):
    x,y,c=sys.stdin.readline().split()
    x,y=int(x),int(y)
    if c=="B":
        if x in bx:
            bx[x]=max(bx[x],y)
        else:
            bx[x]=y
        if y in by:
            by[y]=max(by[y],x)
        else:
            by[y]=x
    if c=="W":
        if x in wx:
            wx[x]=min(wx[x],y)
        else:
            wx[x]=y
        if y in wy:
            wy[y]=min(wy[y],x)
        else:
            wy[y]=x
if len(bx)==0 or len(wx)==0:
    print("Yes")
    exit()

bx_l=[]
by_l=[]
for i in bx:
    bx_l.append([i,bx[i]])
for i in by:
    by_l.append([i,by[i]])
bx_l.sort()
by_l.sort()
bx_len=len(bx_l)
by_len=len(by_l)
bx_x=[0]*bx_len
bx_v=[0]*bx_len
by_y=[0]*by_len
by_v=[0]*by_len

cur=0
for i in range(bx_len):
    cur=max(cur,bx_l[-i-1][1])
    bx_v[-i-1]=cur
    bx_x[-i-1]=bx_l[-i-1][0]
cur=0
for i in range(by_len):
    cur=max(cur,by_l[-i-1][1])
    by_v[-i-1]=cur
    by_y[-i-1]=by_l[-i-1][0]

"""
def bs_x(x):
    l=0
    r=bx_len-1
    if x<=bx_l[0][0]:
        return bx_l[0][1]
    if x>bx_l[r][0]:
        return 0
    while l<r-1:
        mid=(l+r)//2
        if x==bx_l[mid][0]:
            return bx_l[mid][1]
        elif x<bx_l[mid][0]:
            r=mid
        else:
            l=mid
    return bx_l[r][1]

def bs_y(y):
    l=0
    r=by_len-1
    if y<=by_l[0][0]:
        return by_l[0][1]
    if y>by_l[r][0]:
        return 0
    while l<r-1:
        mid=(l+r)//2
        if y==by_l[mid][0]:
            return by_l[mid][1]
        elif y<by_l[mid][0]:
            r=mid
        else:
            l=mid
    return by_l[r][1]
"""

for i in wx:
    v=bisect.bisect_left(bx_x,i)
    if v<bx_len and wx[i]<=bx_v[v]:
        print("No")
        exit()
for j in wy:
    v=bisect.bisect_left(by_y,j)
    if v<by_len and wy[j]<=by_v[v]:
        print("No")
        exit()
print("Yes")

Submission Info

Submission Time
Task D - Diagonal Separation
User keisankatei
Language Python (PyPy 3.10-v7.3.12)
Score 425
Code Size 2126 Byte
Status AC
Exec Time 612 ms
Memory 141948 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 4
AC × 63
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt, 01_test_34.txt, 01_test_35.txt, 01_test_36.txt, 01_test_37.txt, 01_test_38.txt, 01_test_39.txt, 01_test_40.txt, 01_test_41.txt, 01_test_42.txt, 01_test_43.txt, 01_test_44.txt, 01_test_45.txt, 01_test_46.txt, 01_test_47.txt, 01_test_48.txt, 01_test_49.txt, 01_test_50.txt, 01_test_51.txt, 01_test_52.txt, 01_test_53.txt, 01_test_54.txt, 01_test_55.txt, 01_test_56.txt, 01_test_57.txt, 01_test_58.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 59 ms 76412 KB
00_sample_01.txt AC 60 ms 76224 KB
00_sample_02.txt AC 57 ms 76264 KB
00_sample_03.txt AC 63 ms 76220 KB
01_test_00.txt AC 59 ms 76584 KB
01_test_01.txt AC 60 ms 76680 KB
01_test_02.txt AC 64 ms 76260 KB
01_test_03.txt AC 59 ms 76416 KB
01_test_04.txt AC 156 ms 85364 KB
01_test_05.txt AC 154 ms 85736 KB
01_test_06.txt AC 158 ms 85432 KB
01_test_07.txt AC 123 ms 84676 KB
01_test_08.txt AC 118 ms 83732 KB
01_test_09.txt AC 135 ms 85424 KB
01_test_10.txt AC 510 ms 141720 KB
01_test_11.txt AC 361 ms 123512 KB
01_test_12.txt AC 500 ms 141728 KB
01_test_13.txt AC 179 ms 99296 KB
01_test_14.txt AC 612 ms 141672 KB
01_test_15.txt AC 534 ms 131436 KB
01_test_16.txt AC 562 ms 141452 KB
01_test_17.txt AC 337 ms 113588 KB
01_test_18.txt AC 520 ms 141500 KB
01_test_19.txt AC 148 ms 94140 KB
01_test_20.txt AC 555 ms 141948 KB
01_test_21.txt AC 241 ms 105840 KB
01_test_22.txt AC 588 ms 141812 KB
01_test_23.txt AC 176 ms 96508 KB
01_test_24.txt AC 581 ms 141584 KB
01_test_25.txt AC 192 ms 101064 KB
01_test_26.txt AC 498 ms 141752 KB
01_test_27.txt AC 452 ms 135028 KB
01_test_28.txt AC 533 ms 141716 KB
01_test_29.txt AC 275 ms 108560 KB
01_test_30.txt AC 165 ms 119972 KB
01_test_31.txt AC 120 ms 103484 KB
01_test_32.txt AC 179 ms 119840 KB
01_test_33.txt AC 117 ms 100024 KB
01_test_34.txt AC 422 ms 118448 KB
01_test_35.txt AC 346 ms 110836 KB
01_test_36.txt AC 441 ms 117224 KB
01_test_37.txt AC 163 ms 88732 KB
01_test_38.txt AC 395 ms 117032 KB
01_test_39.txt AC 251 ms 100724 KB
01_test_40.txt AC 400 ms 117268 KB
01_test_41.txt AC 177 ms 92668 KB
01_test_42.txt AC 203 ms 99448 KB
01_test_43.txt AC 93 ms 85040 KB
01_test_44.txt AC 179 ms 99304 KB
01_test_45.txt AC 109 ms 90184 KB
01_test_46.txt AC 545 ms 141388 KB
01_test_47.txt AC 185 ms 100368 KB
01_test_48.txt AC 523 ms 141420 KB
01_test_49.txt AC 399 ms 126404 KB
01_test_50.txt AC 537 ms 141604 KB
01_test_51.txt AC 339 ms 123416 KB
01_test_52.txt AC 530 ms 141572 KB
01_test_53.txt AC 485 ms 132076 KB
01_test_54.txt AC 381 ms 116848 KB
01_test_55.txt AC 125 ms 86460 KB
01_test_56.txt AC 384 ms 117652 KB
01_test_57.txt AC 139 ms 87932 KB
01_test_58.txt AC 56 ms 76448 KB


2025-03-05 (Wed)
03:40:25 +00:00