結果
問題 |
No.60 魔法少女
|
ユーザー |
![]() |
提出日時 | 2025-03-20 20:21:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 257 ms / 5,000 ms |
コード長 | 2,031 bytes |
コンパイル時間 | 142 ms |
コンパイル使用メモリ | 82,620 KB |
実行使用メモリ | 148,812 KB |
最終ジャッジ日時 | 2025-03-20 20:22:50 |
合計ジャッジ時間 | 3,198 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 10 |
ソースコード
def main(): import sys input = sys.stdin.read data = input().split() idx = 0 N, K = int(data[idx]), int(data[idx+1]) idx += 2 enemies = [] for _ in range(N): x = int(data[idx]) y = int(data[idx+1]) hp = int(data[idx+2]) enemies.append((x, y, hp)) idx += 3 # Initialize diff array (1002x1002) diff = [[0] * 1002 for _ in range(1002)] for _ in range(K): ax = int(data[idx]) ay = int(data[idx+1]) w = int(data[idx+2]) h = int(data[idx+3]) d = int(data[idx+4]) idx += 5 # Calculate valid x range x_start = max(ax, -500) x_end = min(ax + w, 500) if x_start > x_end: continue # Invalid attack # Calculate valid y range y_start = max(ay, -500) y_end = min(ay + h, 500) if y_start > y_end: continue # Invalid attack # Convert to indices x_s = x_start + 500 x_e = x_end + 500 y_s = y_start + 500 y_e = y_end + 500 # Update diff array diff[x_s][y_s] += d if y_e + 1 < 1002: diff[x_s][y_e + 1] -= d if x_e + 1 < 1002: diff[x_e + 1][y_s] -= d if y_e + 1 < 1002: diff[x_e + 1][y_e + 1] += d # Compute row-wise prefix sums for x in range(1002): current = 0 for y in range(1002): current += diff[x][y] diff[x][y] = current # Compute column-wise prefix sums for y in range(1002): current = 0 for x in range(1002): current += diff[x][y] diff[x][y] = current # Calculate remaining HP result = 0 for x, y, hp in enemies: x_idx = x + 500 y_idx = y + 500 total_damage = diff[x_idx][y_idx] if total_damage < hp: result += (hp - total_damage) print(result) if __name__ == '__main__': main()