Submission #41558048


Source Code Expand

from itertools import product
from collections import defaultdict

H, W = map(int, input().split())
S = [input() for _ in range(H)]

SNUKE = "snuke"
next_char = {
  "s": "n",
  "n": "u",
  "u": "k",
  "k": "e",
  "e": None,
}

chars = defaultdict(set)
for h, w in product(range(H), range(W)):
  if S[h][w] in SNUKE:
    chars[S[h][w]].add((h, w))

f = [
  lambda x: x + 1,
  lambda x: x - 1,
  lambda x: x
]

def search(c, h, w, h_n, w_n):
  ans.append((h + 1, w + 1))
  if c == "e":
    [print(h, w) for h, w in ans]
    exit()
  if (h_n(h), w_n(w)) in chars[next_char[c]]:
    search(next_char[c], h_n(h), w_n(w), h_n, w_n)


for h, w in chars["s"]:
  for h_next, w_next in product(f, f):
    ans = []
    search("s", h, w, h_next, w_next)







Submission Info

Submission Time
Task B - Find snuke
User arakaki_tokyo
Language Python (3.8.2)
Score 250
Code Size 795 Byte
Status AC
Exec Time 47 ms
Memory 10532 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 250 / 250
Status
AC × 3
AC × 33
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt
Case Name Status Exec Time Memory
example_00.txt AC 26 ms 9236 KiB
example_01.txt AC 25 ms 9276 KiB
example_02.txt AC 21 ms 9276 KiB
random_00.txt AC 28 ms 9364 KiB
random_01.txt AC 38 ms 10184 KiB
random_02.txt AC 31 ms 10248 KiB
random_03.txt AC 22 ms 9448 KiB
random_04.txt AC 20 ms 9432 KiB
random_05.txt AC 20 ms 9320 KiB
random_06.txt AC 23 ms 9504 KiB
random_07.txt AC 37 ms 10208 KiB
random_08.txt AC 39 ms 10496 KiB
random_09.txt AC 26 ms 9132 KiB
random_10.txt AC 28 ms 10224 KiB
random_11.txt AC 39 ms 10372 KiB
random_12.txt AC 26 ms 9336 KiB
random_13.txt AC 41 ms 10488 KiB
random_14.txt AC 23 ms 9324 KiB
random_15.txt AC 28 ms 9608 KiB
random_16.txt AC 35 ms 10424 KiB
random_17.txt AC 34 ms 10480 KiB
random_18.txt AC 26 ms 9344 KiB
random_19.txt AC 22 ms 9276 KiB
random_20.txt AC 47 ms 10344 KiB
random_21.txt AC 27 ms 9508 KiB
random_22.txt AC 34 ms 10532 KiB
random_23.txt AC 33 ms 10396 KiB
random_24.txt AC 19 ms 9124 KiB
random_25.txt AC 32 ms 10528 KiB
random_26.txt AC 29 ms 9172 KiB
random_27.txt AC 27 ms 9360 KiB
random_28.txt AC 41 ms 10224 KiB
random_29.txt AC 21 ms 9196 KiB