Submission details
Task:Forest density
Sender:luukwin
Submission time:2025-09-22 16:45:18 +0300
Language:Python3 (PyPy3)
Status:READY
Result:
Test results
testverdicttime
#10.04 sdetails
#20.44 sdetails
#30.38 sdetails

Code

n, q = [int(x) for x in input().split()]

array = [[0 for _ in range(n)] for _ in range(n)]

for i in range(0, n):
    line = input()
    for j in range(0, n):
        if i != 0 and j != 0: array[i][j] = array[i-1][j] + array[i][j-1] - array[i-1][j-1]
        elif i != 0: array[i][j] = array[i-1][j]
        elif j != 0: array[i][j] = array[i][j-1]
        if line[j] == "*": array[i][j] += 1

for line in array: print(line)

output = []
for i in range(q):
    coords = [int(x) - 1 for x in input().split()]
    answer = array[coords[2]][coords[3]]
    if coords[0] != 0: answer -= array[coords[0] - 1][coords[3]]
    if coords[1] != 0: answer -= array[coords[2]][coords[1] - 1]
    output.append(str(answer))

print("\n".join(output))

Test details

Test 1

Verdict:

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

correct output
10
14
5
7
8
...

user output
[1, 2, 2, 3, 3, 4, 4, 5, 6, 6]
[2, 3, 4, 6, 6, 8, 8, 9, 11, 1...
Truncated

Test 2

Verdict:

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

correct output
41079
2824
15631
1548
8483
...

user output
[1, 2, 2, 3, 4, 4, 5, 6, 7, 8,...
Truncated

Test 3

Verdict:

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

correct output
1000000
1000000
1000000
1000000
1000000
...

user output
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10...
Truncated