| Task: | Forest density |
| Sender: | ariadna.roga |
| Submission time: | 2025-09-22 17:47:31 +0300 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | ACCEPTED | 0.58 s | details |
| #3 | ACCEPTED | 0.55 s | details |
Code
#include <iostream>
#include <vector>
using namespace std;
int main() {
long long n, q;
cin >> n >> q;
vector<vector<char>> v(n, vector<char>(n));
vector<vector<long long>> pre(n, vector<long long>(n));
for (long long i = 0; i < n; ++i) {
for (long long j = 0; j < n; ++j) {
cin >> v[i][j];
if (i == 0 and j == 0)
pre[i][j] = 0;
else if (i == 0)
pre[i][j] = pre[i][j - 1];
else if (j == 0)
pre[i][j] = pre[i - 1][j];
else {
pre[i][j] = pre[i - 1][j] + pre[i][j - 1] - pre[i - 1][j - 1];
}
if (v[i][j] == '*')
++pre[i][j];
}
}
for (long long i = 0; i < q; ++i) {
long long y1, x1, y2, x2;
cin >> y1 >> x1 >> y2 >> x2;
int val1, val2, val3, val4;
if (y2-1 < 0 or x2-1 < 0)
val1 = 0;
else
val1 = pre[y2 - 1][x2 - 1];
if (y1-2 < 0 or x2-1 < 0)
val2 = 0;
else
val2 = pre[y1 - 2][x2 - 1];
if (y2 - 1 < 0 or x1-2 < 0)
val3 = 0;
else
val3 = pre[y2 - 1][x1 - 2];
if (y1-2 < 0 or x1-2 < 0)
val4 = 0;
else
val4 = pre[y1 - 2][x1 - 2];
cout << val1 - val2 - val3 + val4 << endl;
}
}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 |
