Submission #57554290


Source Code Expand

H,W,Q = map(int, input().split())

from atcoder.dsu import DSU
uf = DSU(H*W)

wall = [True]*(H*W)

def Id(i,j):
    return i*W + j

def Pos(id):
    return divmod(id,W)

def is_inside(x, y):
    return 0 <= x <= H-1 and 0 <= y <= W-1

moves = [(0,1), (1,0), (0,-1), (-1,0)]

for _ in range(Q):
    # print(uf.groups())
    R,C = map(int, input().split())
    R,C = R-1,C-1
    id = Id(R,C)
    if wall[id]:
        wall[id] = False
        for move in moves:
            next_R, next_C = R+move[0],C+move[1]
            if is_inside(next_R, next_C) and not wall[Id(next_R, next_C)]:
                uf.merge(id, Id(next_R, next_C))
    else:
        group = list(filter(lambda x: id in x, uf.groups()))
        group = group[0]

        yoko = list(filter(lambda x: R*W<=x<=id, group))
        # print(f"{yoko=}")
        left = min(yoko)
        r,c = Pos(left)
        if is_inside(r,c-1):
            wall[left-1] = False
            uf.merge(left-1,left)

        right = max(yoko)
        r,c = Pos(right)
        if is_inside(r,c+1):
            wall[right+1] = False
            uf.merge(right+1,right)
        
        tate = list(filter(lambda x: x%W == C, group))
        # print(f"{tate=}")
        top = min(tate)
        r,c = Pos(top)
        if is_inside(r-1,c):
            wall[top-W] = False
            uf.merge(top,top-W)

        bottom = max(tate)
        r,c = Pos(bottom)
        if is_inside(r+1,c):
            wall[bottom+W] = False
            uf.merge(bottom,bottom+W)

        # print(f"{left=}, {right=}, {top=}, {bottom=}")

print(wall.count(True))

Submission Info

Submission Time
Task D - Cross Explosion
User entropiajp
Language Python (PyPy 3.10-v7.3.12)
Score 0
Code Size 1643 Byte
Status WA
Exec Time 4438 ms
Memory 451492 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 1
WA × 2
AC × 1
WA × 2
TLE × 23
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 02_all_break_00.txt, 03_hack_00.txt, 03_hack_01.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 117 ms 84712 KiB
00_sample_01.txt WA 120 ms 84604 KiB
00_sample_02.txt WA 120 ms 84520 KiB
01_random_00.txt TLE 4437 ms 437160 KiB
01_random_01.txt TLE 4437 ms 446680 KiB
01_random_02.txt TLE 4435 ms 405480 KiB
01_random_03.txt TLE 4435 ms 444380 KiB
01_random_04.txt TLE 4436 ms 444428 KiB
01_random_05.txt TLE 4436 ms 399324 KiB
01_random_06.txt TLE 4435 ms 400872 KiB
01_random_07.txt TLE 4435 ms 401688 KiB
01_random_08.txt TLE 4435 ms 426156 KiB
01_random_09.txt TLE 4435 ms 399940 KiB
01_random_10.txt TLE 4435 ms 399496 KiB
01_random_11.txt TLE 4435 ms 400740 KiB
01_random_12.txt TLE 4438 ms 451492 KiB
01_random_13.txt TLE 4435 ms 402120 KiB
01_random_14.txt TLE 4435 ms 399580 KiB
01_random_15.txt TLE 4435 ms 400336 KiB
01_random_16.txt TLE 4434 ms 397736 KiB
01_random_17.txt TLE 4435 ms 403148 KiB
01_random_18.txt TLE 4436 ms 399696 KiB
01_random_19.txt TLE 4435 ms 399840 KiB
02_all_break_00.txt TLE 4437 ms 439136 KiB
03_hack_00.txt TLE 4436 ms 403692 KiB
03_hack_01.txt TLE 4435 ms 397352 KiB