結果
問題 | No.2411 Reverse Directions |
ユーザー | mkawa2 |
提出日時 | 2023-08-11 22:25:39 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,650 bytes |
コンパイル時間 | 317 ms |
コンパイル使用メモリ | 82,896 KB |
実行使用メモリ | 133,632 KB |
最終ジャッジ日時 | 2024-11-18 17:01:58 |
合計ジャッジ時間 | 17,156 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
59,648 KB |
testcase_01 | AC | 45 ms
129,920 KB |
testcase_02 | TLE | - |
testcase_03 | AC | 48 ms
133,632 KB |
testcase_04 | AC | 88 ms
91,392 KB |
testcase_05 | AC | 45 ms
131,072 KB |
testcase_06 | AC | 44 ms
59,904 KB |
testcase_07 | AC | 93 ms
79,872 KB |
testcase_08 | AC | 44 ms
54,272 KB |
testcase_09 | AC | 45 ms
54,016 KB |
testcase_10 | AC | 220 ms
104,192 KB |
testcase_11 | AC | 45 ms
54,656 KB |
testcase_12 | AC | 181 ms
87,652 KB |
testcase_13 | AC | 51 ms
62,464 KB |
testcase_14 | AC | 123 ms
82,048 KB |
testcase_15 | AC | 87 ms
79,232 KB |
testcase_16 | TLE | - |
testcase_17 | AC | 121 ms
80,128 KB |
testcase_18 | AC | 103 ms
80,640 KB |
testcase_19 | AC | 44 ms
54,400 KB |
testcase_20 | AC | 112 ms
78,208 KB |
testcase_21 | AC | 102 ms
78,464 KB |
testcase_22 | AC | 159 ms
84,352 KB |
testcase_23 | AC | 52 ms
65,024 KB |
testcase_24 | AC | 166 ms
83,584 KB |
testcase_25 | AC | 50 ms
62,080 KB |
testcase_26 | TLE | - |
testcase_27 | AC | 108 ms
76,928 KB |
testcase_28 | AC | 152 ms
87,424 KB |
testcase_29 | AC | 190 ms
91,520 KB |
testcase_30 | AC | 157 ms
87,296 KB |
testcase_31 | TLE | - |
ソースコード
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 = [[-10]*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] != -10: 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="")