結果
問題 | No.2411 Reverse Directions |
ユーザー | mkawa2 |
提出日時 | 2023-08-11 22:22:35 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,648 bytes |
コンパイル時間 | 1,095 ms |
コンパイル使用メモリ | 82,392 KB |
実行使用メモリ | 158,788 KB |
最終ジャッジ日時 | 2024-11-18 16:53:16 |
合計ジャッジ時間 | 10,236 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
62,012 KB |
testcase_01 | AC | 40 ms
138,552 KB |
testcase_02 | AC | 39 ms
62,528 KB |
testcase_03 | AC | 39 ms
55,356 KB |
testcase_04 | AC | 80 ms
86,244 KB |
testcase_05 | AC | 38 ms
55,232 KB |
testcase_06 | AC | 39 ms
55,960 KB |
testcase_07 | AC | 80 ms
79,932 KB |
testcase_08 | AC | 38 ms
55,536 KB |
testcase_09 | AC | 40 ms
56,020 KB |
testcase_10 | AC | 189 ms
104,332 KB |
testcase_11 | AC | 40 ms
54,828 KB |
testcase_12 | AC | 161 ms
87,816 KB |
testcase_13 | AC | 43 ms
62,612 KB |
testcase_14 | AC | 108 ms
81,996 KB |
testcase_15 | AC | 77 ms
79,672 KB |
testcase_16 | AC | 69 ms
76,860 KB |
testcase_17 | AC | 104 ms
80,236 KB |
testcase_18 | AC | 87 ms
80,636 KB |
testcase_19 | AC | 37 ms
55,744 KB |
testcase_20 | AC | 99 ms
78,128 KB |
testcase_21 | TLE | - |
testcase_22 | AC | 136 ms
84,384 KB |
testcase_23 | AC | 47 ms
65,804 KB |
testcase_24 | AC | 144 ms
83,340 KB |
testcase_25 | AC | 44 ms
62,528 KB |
testcase_26 | AC | 62 ms
72,552 KB |
testcase_27 | TLE | - |
testcase_28 | AC | 136 ms
87,940 KB |
testcase_29 | AC | 168 ms
91,352 KB |
testcase_30 | AC | 141 ms
87,796 KB |
testcase_31 | AC | 129 ms
158,788 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="")