| Task: | Forest density |
| Sender: | aalto26dm_043 |
| 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.38 s | details |
| #3 | ACCEPTED | 0.36 s | details |
Code
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, q;
cin >> n >> q;
vector<vector<int>> pref(n + 1, vector<int>(n + 1, 0));
for (int y = 1; y <= n; ++y) {
string row;
cin >> row;
for (int x = 1; x <= n; ++x) {
int has_tree = (row[x - 1] == '*') ? 1 : 0;
pref[y][x] = has_tree
+ pref[y - 1][x]
+ pref[y][x - 1]
- pref[y - 1][x - 1];
}
}
while (q--) {
int y1, x1, y2, x2;
cin >> y1 >> x1 >> y2 >> x2;
int result = pref[y2][x2]
- pref[y1 - 1][x2]
- pref[y2][x1 - 1]
+ pref[y1 - 1][x1 - 1];
cout << result << 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 ... |
