結果
| 問題 | No.2411 Reverse Directions | 
| コンテスト | |
| ユーザー | 👑 | 
| 提出日時 | 2023-08-11 22:19:39 | 
| 言語 | Lua (LuaJit 2.1.1734355927) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 2,204 bytes | 
| コンパイル時間 | 243 ms | 
| コンパイル使用メモリ | 6,692 KB | 
| 実行使用メモリ | 9,984 KB | 
| 最終ジャッジ日時 | 2024-11-18 16:47:46 | 
| 合計ジャッジ時間 | 3,796 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 14 WA * 15 | 
ソースコード
--[[
assert for
3 3 8 2 5
..#
...
#..
]]
local mfl, mce = math.floor, math.ceil
local h, w = io.read("*n", "*n")
local k, l, r = io.read("*n", "*n", "*n", "*l")
local t = {}
local len = {}
for i = 1, h do
  t[i] = {}
  len[i] = {}
  local s = io.read()
  for j = 1, w do
    t[i][j] = s:sub(j, j) == "#"
    len[i][j] = -999
  end
end
local minlen = h + w - 2
if (minlen + k) % 2 == 1 then
  print("No") os.exit()
end
if (r - l) % 2 == 0 then
  print("No") os.exit()
end
if l == 1 then
  print("No") os.exit()
end
len[1][1] = 0
local tasks = {1}
local done = 0
local function walk(dst, dr, dc, l)
  if not t[dr][dc] and len[dr][dc] < 0 then
    len[dr][dc] = l
    table.insert(tasks, dst)
  end
end
while done < #tasks do
  done = done + 1
  local src = tasks[done]
  local row = mce(src / w)
  local col = src - (row - 1) * w
  local l2 = len[row][col] + 1
  if 1 < row then
    walk(src - w, row - 1, col, l2)
  end
  if row < h then
    walk(src + w, row + 1, col, l2)
  end
  if 1 < col then
    walk(src - 1, row, col - 1, l2)
  end
  if col < w then
    walk(src + 1, row, col + 1, l2)
  end
end
if len[h][w] < 0 or k - (r - l + 1) < len[h][w] then
  print("No") os.exit()
end
print("Yes")
local ans = {}
local ph, pw = h, w
while 1 < ph or 1 < pw do
  if 1 < ph and len[ph - 1][pw] + 1 == len[ph][pw] then
    table.insert(ans, "D")
    ph = ph - 1
  elseif ph < h and len[ph + 1][pw] + 1 == len[ph][pw] then
    table.insert(ans, "U")
    ph = ph + 1
  elseif 1 < pw and len[ph][pw - 1] + 1 == len[ph][pw] then
    table.insert(ans, "R")
    pw = pw - 1
  else
    table.insert(ans, "L")
    pw = pw + 1
  end
end
ans = table.concat(ans):reverse()
local rep = mfl((k - len[h][w]) / 2)
if l == 1 then
  assert(false)
  -- if ans:sub(1, 1) == "R" then
    -- print(string.rep("RL", rep) .. ans)
  -- else
    -- print(string.rep("DU", rep) .. ans)
  -- end
else
  io.write(ans:sub(1, l))
  local b = ans:sub(l, l)
  if b == "R" then
    io.write(string.rep("LR", rep))
  elseif b == "L" then
    io.write(string.rep("RL", rep))
  elseif b == "D" then
    io.write(string.rep("UD", rep))
  else
    io.write(string.rep("DU", rep))
  end
  io.write(ans:sub(l + 1, #ans) .. "\n")
  io.flush()
end
            
            
            
        