| Task: | Forest density |
| Sender: | usvafe |
| Submission time: | 2025-09-22 16:38:43 +0300 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | ACCEPTED | 0.56 s | details |
| #3 | ACCEPTED | 0.54 s | details |
Code
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int a[1001][1001];
int main() {
int n, q;
cin >> n >> q;
for (int i=0; i<=n; i++) {
a[0][i] = 0;
a[i][0] = 0;
}
for (int i=1; i<=n; i++) {
for (int j=1; j<=n; j++) {
char b;
cin >> b;
int c;
if (b == '*') c = 1;
else c = 0;
a[i][j] = c + a[i-1][j] + a[i][j-1] - a[i-1][j-1];
}
}
for (int i=0; i<q; i++) {
int y1,x1,y2,x2;
cin >> y1 >> x1 >> y2 >> x2;
int out;
out = a[y2][x2] - a[y1-1][x2] - a[y2][x1-1] + a[y1-1][x1-1];
cout << out << '\n';
}
}
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 |
