結果
問題 | No.2411 Reverse Directions |
ユーザー | 👑 AngrySadEight |
提出日時 | 2023-07-19 23:52:06 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 4,403 bytes |
コンパイル時間 | 415 ms |
コンパイル使用メモリ | 82,396 KB |
実行使用メモリ | 755,704 KB |
最終ジャッジ日時 | 2024-10-09 18:45:45 |
合計ジャッジ時間 | 5,548 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
63,524 KB |
testcase_01 | AC | 43 ms
54,556 KB |
testcase_02 | AC | 42 ms
55,600 KB |
testcase_03 | AC | 41 ms
55,920 KB |
testcase_04 | AC | 83 ms
99,820 KB |
testcase_05 | AC | 41 ms
55,108 KB |
testcase_06 | AC | 43 ms
55,328 KB |
testcase_07 | AC | 99 ms
81,136 KB |
testcase_08 | AC | 41 ms
55,632 KB |
testcase_09 | AC | 42 ms
54,852 KB |
testcase_10 | AC | 261 ms
150,520 KB |
testcase_11 | AC | 43 ms
55,808 KB |
testcase_12 | AC | 231 ms
113,936 KB |
testcase_13 | AC | 45 ms
56,152 KB |
testcase_14 | MLE | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
ソースコード
from collections import deque H, W, K, L, R = map(int, input().split()) S = [] for _ in range(H): s = str(input()) S.append(s) if (R - L + 1) % 2 == 1: print("No") exit() if (H + W - 2) % 2 != K % 2: print("No") exit() dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] c = ['D', 'R', 'U', 'L'] INF = 10000002 dist_s = [[INF for _ in range(W)] for _ in range(H)] dist_t = [[INF for _ in range(W)] for _ in range(H)] dq = deque() dist_s[0][0] = 0 dq.append([0, 0]) while len(dq): px, py = dq.popleft() for i in range(4): if px + dx[i] >= 0 and px + dx[i] < H and py + dy[i] >= 0 and py + dy[i] < W: if S[px + dx[i]][py + dy[i]] == '#': continue if dist_s[px + dx[i]][py + dy[i]] >= INF: dist_s[px + dx[i]][py + dy[i]] = dist_s[px][py] + 1 dq.append([px + dx[i], py + dy[i]]) dist_t[H - 1][W - 1] = 0 dq.append([H - 1, W - 1]) while len(dq): px, py = dq.popleft() for i in range(4): if px + dx[i] >= 0 and px + dx[i] < H and py + dy[i] >= 0 and py + dy[i] < W: if S[px + dx[i]][py + dy[i]] == '#': continue if dist_t[px + dx[i]][py + dy[i]] >= INF: dist_t[px + dx[i]][py + dy[i]] = dist_t[px][py] + 1 dq.append([px + dx[i], py + dy[i]]) dir = [[-1 for _ in range(W)] for _ in range(H)] for i in range(H): for j in range(W): if i > 0 and i < H - 1: if S[i][j] == '.' and S[i - 1][j] == '.' and S[i + 1][j] == '.': dir[i][j] = 1 if j > 0 and j < W - 1: if S[i][j] == '.' and S[i][j - 1] == '.' and S[i][j + 1] == '.': dir[i][j] = 2 idx_x = -1 idx_y = -1 for i in range(H): for j in range(W): if dir[i][j] >= 1: if dist_s[i][j] > L - 1: continue if abs(dist_s[i][j] - (L - 1)) % 2 == 1: continue if dist_t[i][j] > K - R: continue if abs(dist_t[i][j] - (K - R)) % 2 == 1: continue idx_x = i idx_y = j if idx_x == -1: print("No") else: print("Yes") ans_str = [] now_idx_x = idx_x now_idx_y = idx_y ss = [] while True: if now_idx_x == 0 and now_idx_y == 0: break for i in range(4): if now_idx_x + dx[i] >= 0 and now_idx_x + dx[i] < H and now_idx_y + dy[i] >= 0 and now_idx_y + dy[i] < W: if dist_s[now_idx_x + dx[i]][now_idx_y + dy[i]] == dist_s[now_idx_x][now_idx_y] - 1: now_idx_x += dx[i] now_idx_y += dy[i] ss.append(c[(i + 2) % 4]) while True: if len(ss) == L - 1: break if ss[-1] == 'L': ss.append('R') ss.append('L') if ss[-1] == 'R': ss.append('L') ss.append('R') if ss[-1] == 'U': ss.append('D') ss.append('U') if ss[-1] == 'D': ss.append('U') ss.append('D') for i in reversed(range(len(ss))): ans_str.append(ss[i]) if dir[idx_x][idx_y] == 1: for i in range((R - L + 1) // 2): ans_str.append('U') ans_str.append('D') else: for i in range((R - L + 1) // 2): ans_str.append('L') ans_str.append('R') now_idx_x = idx_x now_idx_y = idx_y st = [] while True: if now_idx_x == H - 1 and now_idx_y == W - 1: break for i in range(4): if now_idx_x + dx[i] >= 0 and now_idx_x + dx[i] < H and now_idx_y + dy[i] >= 0 and now_idx_y + dy[i] < W: if dist_t[now_idx_x + dx[i]][now_idx_y + dy[i]] == dist_t[now_idx_x][now_idx_y] - 1: now_idx_x += dx[i] now_idx_y += dy[i] st.append(c[i]) while True: if len(st) == K - R: break if st[-1] == 'L': st.append('R') st.append('L') if st[-1] == 'R': st.append('L') st.append('R') if st[-1] == 'U': st.append('D') st.append('U') if st[-1] == 'D': st.append('U') st.append('D') st += "UD" for i in range(len(st)): ans_str.append(st[i]) print(''.join(ans_str))