| Task: | Forest density |
| Sender: | aalto26dm_035 |
| Submission time: | 2026-09-21 16:53:23 +0300 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | ACCEPTED | 0.57 s | details |
| #3 | ACCEPTED | 0.55 s | details |
Code
#include <iostream>
#include <vector>
#include <numeric>
#include <cstdint>
int main() {
int n, q;
std::cin >> n >> q;
std::vector<std::vector<int>> tree_sum(n, std::vector<int>(n));
for (auto &row : tree_sum) {
for (auto &tree : row) {
char c;
std::cin >> c;
if (c == '.') tree = 0;
else tree = 1;
}
}
for (int i = 0; i < n; ++i) {
for (int j = 1; j < n; ++j) {
tree_sum[i][j] += tree_sum[i][j-1];
}
}
for (int j = 0; j < n; ++j) {
for (int i = 1; i < n; ++i) {
tree_sum[i][j] += tree_sum[i-1][j];
}
}
std::vector<int> outputs(q);
for (int i = 0; i < q; ++i) {
int y_1, x_1, y_2, x_2;
std::cin >> y_1 >> x_1 >> y_2 >> x_2;
int A = tree_sum[y_2-1][x_2-1];
int B = 0, C = 0, D = 0;
if (x_1-1 >= 1) B = tree_sum[y_2-1][x_1-2];
if (y_1-1 >= 1) C = tree_sum[y_1-2][x_2-1];
if (x_1-1 >= 1 && y_1-1 >= 1) D = tree_sum[y_1-2][x_1-2];
outputs[i] = A + D - B - C;
}
for (int i = 0; i < q; ++i) {
std::cout << outputs[i] << std::endl;
}
}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 ... |
