結果

問題 No.60 魔法少女
ユーザー Mao-betaMao-beta
提出日時 2024-03-03 13:52:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 391 ms / 5,000 ms
コード長 1,845 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 163,708 KB
最終ジャッジ日時 2024-03-03 13:52:50
合計ジャッジ時間 6,708 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 227 ms
139,236 KB
testcase_01 AC 224 ms
139,236 KB
testcase_02 AC 225 ms
139,236 KB
testcase_03 AC 225 ms
139,236 KB
testcase_04 AC 319 ms
151,792 KB
testcase_05 AC 334 ms
154,320 KB
testcase_06 AC 383 ms
162,888 KB
testcase_07 AC 373 ms
156,680 KB
testcase_08 AC 304 ms
150,688 KB
testcase_09 AC 267 ms
144,268 KB
testcase_10 AC 388 ms
161,488 KB
testcase_11 AC 255 ms
142,248 KB
testcase_12 AC 306 ms
149,892 KB
testcase_13 AC 391 ms
163,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
import bisect
from heapq import heapify, heappop, heappush
from collections import deque, defaultdict, Counter
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD99 = 998244353

input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
SMI = lambda: input().split()
SLI = lambda: list(SMI())
EI = lambda m: [NLI() for _ in range(m)]


def cum_2D(A):
    """
    2次元リストAの累積和(左と上は0になる)
    """
    H = len(A)
    W = len(A[0])
    C = [[0]*(W+1) for _ in range(H+1)]

    for h in range(H):
        cw = 0
        for w in range(W):
            cw += A[h][w]
            if h == 0 and w == 0:
                C[h+1][w+1] = A[h][w]
            elif h == 0:
                C[h+1][w+1] = A[h][w] + C[h+1][w]
            elif w == 0:
                C[h+1][w+1] = A[h][w] + C[h][w+1]
            else:
                C[h+1][w+1] = C[h][w+1] + cw

    return C


def area_sum(cum, hl, hr, wl, wr):
    """
    2次元累積和の行列cum(左と上は0)から、元の行列の[hl:hr, wl:wr]の範囲で和をとる
    """
    return cum[hr][wr] - cum[hl][wr] - cum[hr][wl] + cum[hl][wl]


def main():
    N, K = NMI()
    E = EI(N)
    A = EI(K)
    M = 2000
    X = [[0]*(M+5) for _ in range(M+5)]
    for x, y, dx, dy, d in A:
        x += 1000
        y += 1000
        X[x][y] += d
        X[x+dx+1][y] -= d
        X[x][y+dy+1] -= d
        X[x+dx+1][y+dy+1] += d
        
    C = cum_2D(X)

    ans = 0
    for x, y, hp in E:
        x += 1001
        y += 1001
        if hp > C[x][y]:
            ans += hp - C[x][y]

    print(ans)


if __name__ == "__main__":
    main()
0