Submission #43122573


Source Code Expand

H, W = map(int, input().split(' '))
v = []
for i in range(H):
    line = input()
    v.append(list(line))

s = "snuke"

def main():
    candidate = set([(0, 0)])
    if v[0][0] != 's':
        return False
    for i in range(1, H * W):
        if len(candidate) < 1:
            return False

        candidate = step(candidate, i)
        # print(s[i % 5], i, candidate)
        if (H-1, W-1) in candidate:
            return True
    if (H - 1, W - 1) in candidate:
        return True
    return False

def step(candidate, i):
    char = s[i % 5]
    new_candidate = set()
    for y, x in candidate:
        for y1, x1 in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            yy = y + y1
            xx = x + x1
            if 0 <= yy < H and 0 <= xx < W:
                # print(yy, xx)
                if v[yy][xx] == char:
                    new_candidate.add((yy, xx))
    return new_candidate

if main():
    print('Yes')
else:
    print('No')

Submission Info

Submission Time
Task D - Snuke Maze
User cocodrips
Language PyPy3 (7.3.0)
Score 0
Code Size 988 Byte
Status TLE
Exec Time 2211 ms
Memory 222748 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 20
TLE × 16
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, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 02_random2_10.txt, 02_random2_11.txt, 02_random2_12.txt, 02_random2_13.txt, 02_random2_14.txt, 02_random2_15.txt, 02_random2_16.txt, 02_random2_17.txt, 02_random2_18.txt, 02_random2_19.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 62 ms 61832 KiB
00_sample_01.txt AC 48 ms 61848 KiB
00_sample_02.txt AC 50 ms 61744 KiB
01_random_00.txt AC 51 ms 62568 KiB
01_random_01.txt AC 58 ms 69216 KiB
01_random_02.txt AC 69 ms 77184 KiB
01_random_03.txt AC 54 ms 64976 KiB
01_random_04.txt AC 54 ms 68392 KiB
01_random_05.txt AC 49 ms 61872 KiB
01_random_06.txt AC 54 ms 62540 KiB
01_random_07.txt AC 52 ms 64800 KiB
02_random2_00.txt TLE 2211 ms 221424 KiB
02_random2_01.txt TLE 2211 ms 222076 KiB
02_random2_02.txt TLE 2211 ms 222408 KiB
02_random2_03.txt TLE 2211 ms 222396 KiB
02_random2_04.txt TLE 2211 ms 221948 KiB
02_random2_05.txt AC 85 ms 77664 KiB
02_random2_06.txt TLE 2211 ms 222328 KiB
02_random2_07.txt TLE 2211 ms 222328 KiB
02_random2_08.txt TLE 2211 ms 221300 KiB
02_random2_09.txt AC 190 ms 84176 KiB
02_random2_10.txt TLE 2211 ms 222204 KiB
02_random2_11.txt AC 451 ms 83764 KiB
02_random2_12.txt TLE 2211 ms 221880 KiB
02_random2_13.txt TLE 2211 ms 222748 KiB
02_random2_14.txt AC 203 ms 83260 KiB
02_random2_15.txt TLE 2211 ms 221920 KiB
02_random2_16.txt AC 148 ms 83088 KiB
02_random2_17.txt AC 337 ms 84000 KiB
02_random2_18.txt TLE 2211 ms 222520 KiB
02_random2_19.txt TLE 2211 ms 221288 KiB
03_handmade_00.txt AC 63 ms 61904 KiB
03_handmade_01.txt AC 140 ms 83484 KiB
03_handmade_02.txt AC 142 ms 83316 KiB
03_handmade_03.txt TLE 2211 ms 221480 KiB
03_handmade_04.txt TLE 2211 ms 221364 KiB