Submission #57533181


Source Code Expand

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

ds = [{} for i in range(4)]
dx, dy = [0, 1, 0, -1], [1, 0, -1, 0]
dd = {}

def get(x, y, di):
    if (x, y) in ds[di]:
        nx, ny = ds[di][(x, y)]
    else:
        nx, ny = x, y
    nx, ny = nx + dx[di], ny + dy[di]
    if 1 <= nx <= H and 1 <= ny <= W and (nx, ny) in dd:
        nx, ny = get(nx, ny, di)
    else:
        nx, ny = nx - dx[di], ny - dy[di]
    ds[di][(x, y)] = (nx, ny)
    # print('  get', x, y, di, nx, ny)
    return nx, ny

def add(x, y):
    # print('   ', x, y)
    dd[(x, y)] = 1
    for di in range(4):
        nx, ny = get(x, y, di)



for i in range(Q):
    x, y = map(int, input().split())
    if (x, y) not in dd:
        # print('add', x, y)
        add(x, y)
    else:
        # print('ask', x, y)
        todos = set()
        for di in range(4):
            nx, ny = get(x, y, di)
            nx, ny = nx + dx[di], ny + dy[di]
            if 1 <= nx <= H and 1 <= ny <= W:
                todos.add((nx, ny))
        for nx, ny in todos:
            add(nx, ny)

print(H*W - len(dd))
        

Submission Info

Submission Time
Task D - Cross Explosion
User yefllower
Language Python (PyPy 3.10-v7.3.12)
Score 0
Code Size 1115 Byte
Status TLE
Exec Time 4432 ms
Memory 390372 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 19
TLE × 7
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 61 ms 76744 KiB
00_sample_01.txt AC 62 ms 76452 KiB
00_sample_02.txt AC 62 ms 76368 KiB
01_random_00.txt AC 3906 ms 337792 KiB
01_random_01.txt AC 1492 ms 336160 KiB
01_random_02.txt AC 1823 ms 331888 KiB
01_random_03.txt AC 3804 ms 358252 KiB
01_random_04.txt TLE 4429 ms 390372 KiB
01_random_05.txt TLE 4430 ms 388852 KiB
01_random_06.txt TLE 4429 ms 388280 KiB
01_random_07.txt AC 2125 ms 332464 KiB
01_random_08.txt AC 1545 ms 330164 KiB
01_random_09.txt TLE 4430 ms 387544 KiB
01_random_10.txt AC 2203 ms 328484 KiB
01_random_11.txt AC 3136 ms 350388 KiB
01_random_12.txt AC 3597 ms 352880 KiB
01_random_13.txt TLE 4429 ms 387068 KiB
01_random_14.txt AC 2621 ms 347288 KiB
01_random_15.txt TLE 4429 ms 389460 KiB
01_random_16.txt AC 3282 ms 347416 KiB
01_random_17.txt AC 3310 ms 386876 KiB
01_random_18.txt TLE 4432 ms 386688 KiB
01_random_19.txt AC 2479 ms 344652 KiB
02_all_break_00.txt AC 2341 ms 371116 KiB
03_hack_00.txt AC 804 ms 324784 KiB
03_hack_01.txt AC 724 ms 326124 KiB