結果

問題 No.60 魔法少女
ユーザー simansiman
提出日時 2022-02-22 15:31:31
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,128 ms / 5,000 ms
コード長 780 bytes
コンパイル時間 38 ms
コンパイル使用メモリ 11,260 KB
実行使用メモリ 58,644 KB
最終ジャッジ日時 2023-09-13 06:19:03
合計ジャッジ時間 13,973 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 635 ms
50,760 KB
testcase_01 AC 645 ms
50,792 KB
testcase_02 AC 637 ms
50,992 KB
testcase_03 AC 633 ms
50,772 KB
testcase_04 AC 886 ms
53,176 KB
testcase_05 AC 944 ms
57,892 KB
testcase_06 AC 1,128 ms
57,800 KB
testcase_07 AC 984 ms
56,908 KB
testcase_08 AC 861 ms
55,748 KB
testcase_09 AC 723 ms
53,304 KB
testcase_10 AC 1,107 ms
57,728 KB
testcase_11 AC 674 ms
52,188 KB
testcase_12 AC 837 ms
56,904 KB
testcase_13 AC 1,127 ms
58,644 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Array
  def imos
    h = size
    w = self[0].size

    ret = map(&:dup)

    0.upto(h - 1) do |i|
      1.upto(w - 1) do |j|
        ret[i][j] += ret[i][j - 1]
      end
    end

    1.upto(h - 1) do |i|
      0.upto(w - 1) do |j|
        ret[i][j] += ret[i - 1][j]
      end
    end

    ret
  end
end

geta = 500
S = geta * 3 + 10
N, K = gets.split.map(&:to_i)
E = N.times.map { gets.split.map(&:to_i) }

arr = Array.new(S) { Array.new(S, 0) }

K.times do
  x, y, w, h, d = gets.split.map(&:to_i)
  x += geta
  y += geta

  arr[y][x] += d
  arr[y][x + w + 1] -= d
  arr[y + h + 1][x] -= d
  arr[y + h + 1][x + w + 1] += d
end

arr = arr.imos
ans = 0

E.each do |x, y, hp|
  x += geta
  y += geta
  r_hp = hp - arr[y][x]
  r_hp = 0 if r_hp < 0
  ans += r_hp
end

puts ans
0