結果

問題 No.60 魔法少女
ユーザー rpy3cpprpy3cpp
提出日時 2015-07-28 19:30:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,196 ms / 5,000 ms
コード長 1,317 bytes
コンパイル時間 522 ms
コンパイル使用メモリ 11,092 KB
実行使用メモリ 74,556 KB
最終ジャッジ日時 2023-09-24 12:28:45
合計ジャッジ時間 11,520 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 272 ms
32,116 KB
testcase_01 AC 252 ms
32,052 KB
testcase_02 AC 251 ms
32,052 KB
testcase_03 AC 278 ms
39,640 KB
testcase_04 AC 747 ms
70,384 KB
testcase_05 AC 818 ms
69,608 KB
testcase_06 AC 1,188 ms
74,356 KB
testcase_07 AC 923 ms
71,624 KB
testcase_08 AC 728 ms
68,416 KB
testcase_09 AC 500 ms
65,512 KB
testcase_10 AC 1,104 ms
73,568 KB
testcase_11 AC 383 ms
63,408 KB
testcase_12 AC 653 ms
67,424 KB
testcase_13 AC 1,196 ms
74,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Imos2D():
    def __init__(self, W, H):
        self.W = W
        self.H = H
        self.data = [[0] * (W + 1) for w in range(H + 1)]

    def range_add(self, x1, y1, w, h, d):
        x2 = min(x1 + w + 1, self.W)
        y2 = min(y1 + h + 1, self.H)
        data = self.data
        data[y1][x1] += d
        data[y1][x2] -= d
        data[y2][x1] -= d
        data[y2][x2] += d

    def read_all(self):
        decoded = [[0] * self.W for h in range(self.H)]
        current_row = [0] * self.W
        for y, row in enumerate(self.data[:-1]):
            prev_row = current_row
            current_row = decoded[y]
            cum = 0
            for x, val in enumerate(row[:-1]):
                cum += val
                current_row[x] = cum + prev_row[x]
        return decoded


X = 500
Y = 500
N, K = map(int, input().split())
HP = [[0] * (2 * Y + 1) for w in range(2 * X + 1)]
for n in range(N):
    x, y, hp = map(int, input().split())
    HP[y + Y][x + X] = hp
attacks = Imos2D(X * 2 + 1, Y * 2 + 1)
for k in range(K):
    ax, ay, w, h, d = map(int, input().split())
    attacks.range_add(ax + X, ay + Y, w, h, d)
damage = attacks.read_all()
cumsum = 0
for row_d, row_hp in zip(damage, HP):
    for d, hp in zip(row_d, row_hp):
        if hp and hp > d:
            cumsum += hp - d
print(cumsum)
0