| Task: | Forest density |
| Sender: | aalto26dm_024 |
| Submission time: | 2026-09-21 17:23:31 +0300 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.04 s | details |
| #2 | ACCEPTED | 0.63 s | details |
| #3 | ACCEPTED | 0.57 s | details |
Code
def main():
n, q = [int(x) for x in input().split()]
pref = [[0] * (n + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
row = input().strip()
for j in range(1, n + 1):
val = 1 if row[j - 1] == "*" else 0
pref[i][j] = val + pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1]
for _ in range(q):
area = [int(x) for x in input().split()]
y1, x1, y2, x2 = area
res = pref[y2][x2] - pref[y1 - 1][x2] - pref[y2][x1 - 1] + pref[y1 - 1][x1 - 1]
print(res)
main()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 ... |
