| Task: | Forest density |
| Sender: | aalto26dm_033 |
| Submission time: | 2026-09-21 16:33:39 +0300 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | ACCEPTED | 0.58 s | details |
| #3 | ACCEPTED | 0.56 s | details |
Code
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
vector<vector<int>> pref(n + 1, vector<int>(n + 1, 0));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
char c;
cin >> c;
int has_tree = (c == '*') ? 1 : 0;
pref[i][j] = pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + has_tree;
}
}
while (q--) {
int y1, x1, y2, x2;
cin >> y1 >> x1 >> y2 >> x2;
int total_trees = pref[y2][x2] - pref[y1 - 1][x2] - pref[y2][x1 - 1] + pref[y1 - 1][x1 - 1];
cout << total_trees << "\n";
}
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 ... |
