| Task: | Forest density |
| Sender: | aalto26dm_010 |
| Submission time: | 2026-09-21 17:08:04 +0300 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.04 s | details |
| #2 | ACCEPTED | 0.62 s | details |
| #3 | ACCEPTED | 0.55 s | details |
Code
n, q = map(int, input().split())
forest = [[] for _ in range(n)]
for y in range(n):
row = input().strip()
row_trees = 0
for x, c in enumerate(row):
if c == "*":
row_trees += 1
temp = row_trees
if y != 0:
temp += forest[y-1][x]
forest[y].append(temp)
def get_value(arr: list, y: int, x: int):
if y < 0 or x < 0:
return 0
return arr[y][x]
for _ in range(q):
y1, x1, y2, x2 = map(lambda x: int(x) - 1, input().split())
A = get_value(forest, y2, x2)
B = get_value(forest, y2, x1-1)
C = get_value(forest, y1-1, x2)
D = get_value(forest, y1-1, x1-1)
count = A - B - C + D
print(count)
Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 10 100 **.*.*.**. *.**.*..*. .*****.**. **....***. ... |
| correct output |
|---|
| 10 14 5 7 8 ... |
| user output |
|---|
| 10 14 5 7 8 ... |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 1000 200000 **.**.****..**.***..**.***.**.... |
| correct output |
|---|
| 41079 2824 15631 1548 8483 ... |
| user output |
|---|
| 41079 2824 15631 1548 8483 ... |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 1000 200000 ******************************... |
| correct output |
|---|
| 1000000 1000000 1000000 1000000 1000000 ... |
| user output |
|---|
| 1000000 1000000 1000000 1000000 1000000 ... |
