Submission details
Task:Forest density
Sender:kookinnam
Submission time:2025-09-22 17:09:46 +0300
Language:Python3 (PyPy3)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.04 sdetails
#2ACCEPTED0.60 sdetails
#3ACCEPTED0.55 sdetails

Code

def main():
    n, q = map(int, input().split())

    forest = [list(map(str, input())) for _ in range(n)]
    commands = [list(map(int, input().split())) for _ in range(q)]
    for i in range(n):
        for j in range(n):
            if forest[i][j] == "*":
                forest[i][j] = 1
            else:
                forest[i][j] = 0
    prefix = [[0]*(n+1) for _ in range(n+1)]
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            prefix[i][j] = prefix[i][j - 1] + prefix[i - 1][j] + forest[i - 1][j - 1] - prefix[i - 1][j - 1]


    for command in commands:
        y1, x1, y2, x2 = command
        res = prefix[y2][x2] - prefix[y2][x1-1] - prefix[y1-1][x2] + prefix[y1-1][x1-1]
        print(res)




if __name__ == "__main__":
    main()

Test details

Test 1

Verdict: ACCEPTED

input
10 100
**.*.*.**.
*.**.*..*.
.*****.**.
**....***.
...

correct output
10
14
5
7
8
...

user output
10
14
5
7
8
...
Truncated

Test 2

Verdict: ACCEPTED

input
1000 200000
**.**.****..**.***..**.***.**....

correct output
41079
2824
15631
1548
8483
...

user output
41079
2824
15631
1548
8483
...
Truncated

Test 3

Verdict: ACCEPTED

input
1000 200000
******************************...

correct output
1000000
1000000
1000000
1000000
1000000
...

user output
1000000
1000000
1000000
1000000
1000000
...
Truncated