| Task: | Forest density |
| Sender: | aalto26dm_007 |
| Submission time: | 2026-09-21 17:50:45 +0300 |
| Language: | Python3 (PyPy3) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.04 s | details |
| #2 | OUTPUT LIMIT EXCEEDED | 0.00 s | details |
| #3 | OUTPUT LIMIT EXCEEDED | 0.00 s | details |
Code
import sys
input = sys.stdin.readline
class PrefixSum2D:
def __init__(self, grid):
r = len(grid)
c = len(grid[0]) if r else 0
self.p = [[0] * (c + 1) for _ in range(r + 1)]
for i in range(r):
for j in range(c):
self.p[i + 1][j + 1] = (
grid[i][j]
+ self.p[i][j + 1]
+ self.p[i + 1][j]
- self.p[i][j]
)
def sum_rect(self, r1, c1, r2, c2):
"""Inclusive rectangle from (r1, c1) to (r2, c2)."""
return (
self.p[r2 + 1][c2 + 1]
- self.p[r1][c2 + 1]
- self.p[r2 + 1][c1]
+ self.p[r1][c1]
)
def main():
n, q = map(int, input().split())
grid = [[0]*n]*n
print(grid)
for j in range(n):
line = input()
insert = [0]*n
i = 0
for emo in line:
if emo == '*':
insert[i] = 1
print('yes')
i += 1
print(insert)
grid[j] = insert
print(grid)
prefix = PrefixSum2D(grid)
out = []
for _ in range(q):
a1, a2, b1, b2 = map(int, input().split())
out.append(str(prefix.sum_rect(a1 - 1, a2 -1, b1 - 1, b2 -1)))
sys.stdout.write("\n".join(out) + ("\n" if out else ""))
if __name__ == "__main__":
main()Test details
Test 1
Verdict: WRONG ANSWER
| input |
|---|
| 10 100 **.*.*.**. *.**.*..*. .*****.**. **....***. ... |
| correct output |
|---|
| 10 14 5 7 8 ... |
| user output |
|---|
| [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0... |
Feedback: Output is longer than expected
Test 2
Verdict: OUTPUT LIMIT EXCEEDED
| input |
|---|
| 1000 200000 **.**.****..**.***..**.***.**.... |
| correct output |
|---|
| 41079 2824 15631 1548 8483 ... |
| user output |
|---|
| (empty) |
Test 3
Verdict: OUTPUT LIMIT EXCEEDED
| input |
|---|
| 1000 200000 ******************************... |
| correct output |
|---|
| 1000000 1000000 1000000 1000000 1000000 ... |
| user output |
|---|
| (empty) |
