結果

問題 No.1490 スライムと爆弾
ユーザー 👑 obakyanobakyan
提出日時 2021-04-30 21:12:53
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 371 ms / 2,000 ms
コード長 1,489 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 5,328 KB
実行使用メモリ 41,672 KB
最終ジャッジ日時 2023-09-26 02:34:16
合計ジャッジ時間 7,926 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 160 ms
27,188 KB
testcase_14 AC 185 ms
32,492 KB
testcase_15 AC 135 ms
31,144 KB
testcase_16 AC 125 ms
24,124 KB
testcase_17 AC 113 ms
23,932 KB
testcase_18 AC 181 ms
30,024 KB
testcase_19 AC 187 ms
37,020 KB
testcase_20 AC 148 ms
34,188 KB
testcase_21 AC 117 ms
32,356 KB
testcase_22 AC 153 ms
29,892 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 266 ms
41,672 KB
testcase_26 AC 272 ms
41,456 KB
testcase_27 AC 270 ms
41,320 KB
testcase_28 AC 267 ms
36,536 KB
testcase_29 AC 267 ms
37,000 KB
testcase_30 AC 371 ms
41,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mmi, mma = math.min, math.max
local h, w = io.read("*n", "*n")
local n, m = io.read("*n", "*n")
local r1, r2, c1, c2, a = {}, {}, {}, {}, {}
for i = 1, n do
  r1[i], r2[i], c1[i], c2[i], a[i] = io.read("*n", "*n", "*n", "*n", "*n")
end

local t = {}
for i = 1, h do
  t[i] = {}
  for j = 1, w do
    t[i][j] = 0
  end
end
for i = 1, m do
  local x, y, b, c = io.read("*n", "*n", "*n", "*n")
  local rowmin = mma(1, x - b)
  local rowmax = mmi(h, x + b)
  local colmin = mma(1, y - b)
  local colmax = mmi(w, y + b)
  t[rowmin][colmin] = t[rowmin][colmin] + c
  if rowmax < h then
    t[rowmax + 1][colmin] = t[rowmax + 1][colmin] - c
  end
  if colmax < w then
    t[rowmin][colmax + 1] = t[rowmin][colmax + 1] - c
  end
  if rowmax < h and colmax < w then
    t[rowmax + 1][colmax + 1] = t[rowmax + 1][colmax + 1] + c
  end
end
for i = 1, h do
  for j = 1, w - 1 do
    t[i][j + 1] = t[i][j + 1] + t[i][j]
  end
end
for j = 1, w do
  for i = 1, h - 1 do
    t[i + 1][j] = t[i + 1][j] + t[i][j]
  end
end
for i = 1, h do
  for j = 1, w - 1 do
    t[i][j + 1] = t[i][j + 1] + t[i][j]
  end
end
for j = 1, w do
  for i = 1, h - 1 do
    t[i + 1][j] = t[i + 1][j] + t[i][j]
  end
end
local ret = 0
for i = 1, n do
  local v = t[r2[i]][c2[i]]
  if 1 < r1[i] then
    v = v - t[r1[i] - 1][c2[i]]
  end
  if 1 < c1[i] then
    v = v - t[r2[i]][c1[i] - 1]
  end
  if 1 < r1[i] and 1 < c1[i] then
    v = v + t[r1[i] - 1][c1[i] - 1]
  end
  if v < a[i] then ret = ret + 1 end
end
print(ret)
0