| Task: | Forest density |
| Sender: | aalto26dm_015 |
| Submission time: | 2026-09-21 16:56:07 +0300 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | ACCEPTED | 0.41 s | details |
| #3 | ACCEPTED | 0.38 s | details |
Code
#include <bits/stdc++.h>
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
long n, q;
std::cin >> n >> q;
std::vector map(n + 1, std::vector(n+1, 0));
for (long i = 1; i <= n; i++) {
map[1][i] = map[1][i-1];
char c;
std::cin >> c;
if (c == '*') {
map[1][i]++;
}
}
for (long y = 2; y <= n; y++) {
for (long x = 1; x <= n; x++) {
map[y][x] = map[y][x-1] + map[y-1][x] - map[y-1][x-1];
char c;
std::cin >> c;
if (c == '*') {
map[y][x]++;
}
}
}
for (long i = 0; i < q; i++) {
long y1,x1,y2,x2;
std::cin >> y1 >> x1 >> y2 >> x2;
std::cout << (map[y2][x2] - map[y1 - 1][x2] - map[y2][x1 - 1] + map[y1 - 1][x1 - 1]) << std::endl;
}
std::cout << std::endl;
return 0;
}
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 ... |
