結果
問題 | No.2411 Reverse Directions |
ユーザー | mkawa2 |
提出日時 | 2023-08-11 22:20:19 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,648 bytes |
コンパイル時間 | 287 ms |
コンパイル使用メモリ | 82,184 KB |
実行使用メモリ | 158,848 KB |
最終ジャッジ日時 | 2024-11-18 16:49:19 |
合計ジャッジ時間 | 11,339 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
61,716 KB |
testcase_01 | AC | 44 ms
137,440 KB |
testcase_02 | AC | 44 ms
61,416 KB |
testcase_03 | AC | 43 ms
54,780 KB |
testcase_04 | AC | 87 ms
85,888 KB |
testcase_05 | AC | 45 ms
54,984 KB |
testcase_06 | AC | 44 ms
55,828 KB |
testcase_07 | WA | - |
testcase_08 | AC | 44 ms
55,488 KB |
testcase_09 | AC | 44 ms
54,304 KB |
testcase_10 | AC | 218 ms
104,320 KB |
testcase_11 | AC | 44 ms
54,656 KB |
testcase_12 | AC | 177 ms
87,800 KB |
testcase_13 | AC | 49 ms
62,464 KB |
testcase_14 | AC | 127 ms
81,812 KB |
testcase_15 | AC | 86 ms
79,744 KB |
testcase_16 | AC | 81 ms
76,672 KB |
testcase_17 | AC | 121 ms
80,128 KB |
testcase_18 | AC | 101 ms
80,768 KB |
testcase_19 | AC | 45 ms
54,400 KB |
testcase_20 | AC | 115 ms
78,464 KB |
testcase_21 | TLE | - |
testcase_22 | WA | - |
testcase_23 | AC | 51 ms
64,896 KB |
testcase_24 | WA | - |
testcase_25 | AC | 50 ms
62,080 KB |
testcase_26 | AC | 71 ms
72,192 KB |
testcase_27 | TLE | - |
testcase_28 | AC | 149 ms
87,552 KB |
testcase_29 | AC | 190 ms
91,136 KB |
testcase_30 | AC | 157 ms
87,552 KB |
testcase_31 | AC | 144 ms
158,848 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]*((k-rdd[mi][mj]-dd[mi][mj])//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="")