結果
問題 | No.2411 Reverse Directions |
ユーザー | mkawa2 |
提出日時 | 2023-08-11 22:08:44 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,627 bytes |
コンパイル時間 | 229 ms |
コンパイル使用メモリ | 82,320 KB |
実行使用メモリ | 158,752 KB |
最終ジャッジ日時 | 2024-11-18 16:31:29 |
合計ジャッジ時間 | 12,360 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
62,136 KB |
testcase_01 | AC | 45 ms
134,136 KB |
testcase_02 | AC | 45 ms
61,984 KB |
testcase_03 | AC | 45 ms
55,752 KB |
testcase_04 | AC | 88 ms
85,952 KB |
testcase_05 | AC | 45 ms
55,192 KB |
testcase_06 | AC | 44 ms
54,864 KB |
testcase_07 | WA | - |
testcase_08 | AC | 46 ms
54,852 KB |
testcase_09 | AC | 46 ms
55,040 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 51 ms
63,464 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 81 ms
76,616 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 45 ms
54,804 KB |
testcase_20 | WA | - |
testcase_21 | TLE | - |
testcase_22 | WA | - |
testcase_23 | AC | 54 ms
66,280 KB |
testcase_24 | WA | - |
testcase_25 | AC | 51 ms
62,536 KB |
testcase_26 | AC | 72 ms
72,836 KB |
testcase_27 | TLE | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 148 ms
158,752 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) # sys.set_int_max_str_digits(1000005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = -1-(-1 << 63) # md = 10**9+7 md = 998244353 from collections import deque def bfs(si, sj): dp = [[-1]*w for _ in range(h)] q = deque() q.append((si, sj)) dp[si][sj] = 0 while q: i, j = q.popleft() d = dp[i][j] for di, dj in dij: ni, nj = i+di, j+dj if ni < 0 or nj < 0 or ni >= h or nj >= w: continue if ss[ni][nj]: continue if dp[ni][nj] != -1: continue dp[ni][nj] = d+1 q.append((ni, nj)) return dp def find_mij(): for i in range(h): for j in range(w): if ss[i][j]: continue if dd[i][j] & 1 != l & 1: continue if dd[i][j] > l: continue if rdd[i][j] & 1 != k-r & 1: continue if rdd[i][j] > k-r: continue if i and i+1 < h and ss[i-1][j] == ss[i+1][j] == 0: return i, j, 0 if j and j+1 < w and ss[i][j-1] == ss[i][j-1] == 0: return i, j, 1 return -1, -1, -1 h, w, k, l, r = LI() l -= 1 ss = [[c == "#" for c in SI()] for _ in range(h)] if (r-l) & 1: print("No") exit() dd = bfs(0, 0) rdd = bfs(h-1, w-1) # p2D(dd) # p2D(rdd) mi, mj, dir = find_mij() # pDB(mi,mj,dir) if mi == -1: print("No") exit() ans = [] i, j = mi, mj t = "LDRU" while (i, j) != (0, 0): for p, (di, dj) in enumerate(dij): ni, nj = i+di, j+dj if ni < 0 or nj < 0 or ni >= h or nj >= w: continue if dd[ni][nj] == dd[i][j]-1: ans.append(t[p]) i, j = ni, nj break ans.reverse() t = "LR" if dir else "UD" ans += [t]*((r-l)//2) i, j = mi, mj t = "RULD" while (i, j) != (h-1, w-1): for p, (di, dj) in enumerate(dij): ni, nj = i+di, j+dj if ni < 0 or nj < 0 or ni >= h or nj >= w: continue if rdd[ni][nj] == rdd[i][j]-1: ans.append(t[p]) i, j = ni, nj break print("Yes") print(*ans,sep="")