BOJ - 16507 - 어두운 건 무서워

Updated:

import sys

def solution():
    R, C, Q = map(int, sys.stdin.readline().split())
    maps = []
    for _ in range(R):
        maps.append(list(map(int, sys.stdin.readline().split())))

    dp = [[0 for _ in range(C+1)] for _ in range(R+1)]
    for i in range(1, R+1):
        for j in range(1, C+1):
            dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + maps[i-1][j-1]

    for _ in range(Q):
        r1, c1, r2, c2 = map(int, sys.stdin.readline().split())
        print(
            (dp[r2][c2] - dp[r2][c1-1] - dp[r1-1][c2] + dp[r1-1][c1-1]) // ((r2 - r1 + 1) * (c2 - c1 + 1))
        )

solution()

https://www.acmicpc.net/problem/16507

Categories:

Updated:

Leave a comment