結果
| 問題 |
No.1948 足し算するだけのパズルゲーム(1)
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2022-05-28 21:36:52 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 82 ms / 2,000 ms |
| コード長 | 1,232 bytes |
| コンパイル時間 | 372 ms |
| コンパイル使用メモリ | 6,816 KB |
| 実行使用メモリ | 8,832 KB |
| 最終ジャッジ日時 | 2024-09-20 23:38:45 |
| 合計ジャッジ時間 | 3,415 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
local mmi, mma = math.min, math.max
local h, w = io.read("*n", "*n")
local a = {}
for i = 1, h do
a[i] = {}
for j = 1, w do
a[i][j] = io.read("*n")
end
end
local t1, t2 = {}, {}
for i = 1, h do
t1[i], t2[i] = {}, {}
for j = 1, w do
t1[i][j], t2[i][j] = 0, 0
end
end
t1[1][1] = a[1][1]
for i = 1, h do
for j = 1, w do
if 0 < t1[i][j] then
if i < h then
if (i + 1) * j ~= h * w then t2[i + 1][j] = mma(t2[i + 1][j], t1[i][j]) end
if a[i + 1][j] < t1[i][j] then
t1[i + 1][j] = mma(t1[i + 1][j], a[i + 1][j] + t1[i][j])
end
end
if j < w then
if i * (j + 1) ~= h * w then t2[i][j + 1] = mma(t2[i][j + 1], t1[i][j]) end
if a[i][j + 1] < t1[i][j] then
t1[i][j + 1] = mma(t1[i][j + 1], a[i][j + 1] + t1[i][j])
end
end
end
if 0 < t2[i][j] then
if i < h then
if a[i + 1][j] < t2[i][j] then
t2[i + 1][j] = mma(t2[i + 1][j], a[i + 1][j] + t2[i][j])
end
end
if j < w then
if a[i][j + 1] < t2[i][j] then
t2[i][j + 1] = mma(t2[i][j + 1], a[i][j + 1] + t2[i][j])
end
end
end
end
end
print((0 < t1[h][w] or 0 < t2[h][w]) and "Yes" or "No")