Task: | Forest density |
Sender: | bielaltes |
Submission time: | 2024-09-23 17:26:23 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.53 s | details |
#3 | ACCEPTED | 0.51 s | details |
Code
#include <iostream> #include <vector> using namespace std; int main() { int n, q; cin >> n >> q; vector<string> forest(n); for (int i = 0; i < n; ++i) { cin >> forest[i]; } vector<vector<int>> pre(n + 1, vector<int>(n + 1, 0)); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { if (forest[i-1][j-1] == '*') pre[i][j] = 1 + pre[i-1][j] + pre[i][j-1] - pre[i-1][j-1]; else pre[i][j] = pre[i-1][j] + pre[i][j-1] - pre[i-1][j-1]; } } for (int i = 0; i < q; ++i) { int y1, x1, y2, x2; cin >> y1 >> x1 >> y2 >> x2; int result = pre[y2][x2] - pre[y1-1][x2] - pre[y2][x1-1] + pre[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 ... 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 |