Submission details
Task:Forest density
Sender:ileska
Submission time:2025-09-24 14:16:34 +0300
Language:C++ (C++20)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.55 sdetails
#3ACCEPTED0.54 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int' and 'unsigned int' [-Wsign-compare]
   41 |   for (int yy = 0; yy < size; yy++) {
      |                    ~~~^~~~~~
input/code.cpp:43:25: warning: comparison of integer expressions of different signedness: 'int' and 'unsigned int' [-Wsign-compare]
   43 |     for (int xx = 0; xx < size; xx++) {
      |                      ~~~^~~~~~

Code

#include <iostream>
// #include <string>
#include <vector>
// def getSubSum(startY,startX,endY,endX):
//     # print(sumMap[endY][endX],endX,endY)
//     # print(sumMap[startY][startX],startX,startY)
//     ret = sumMap[endY][endX]
//     if startY != 0:
//         ret -= sumMap[startY-1][endX]
//     if startX != 0:
//         ret -= sumMap[endY][startX-1]
//     if startY != 0 and startX != 0:
//     return ret//         ret += sumMap[startY-1][startX-1]

int getSubSum(int x0, int y0, int x1, int y1, std::vector<int> &sumMap,
              int size) {
  // std::cout << startX << std::endl;
  // std::cout << sumMap[y1 * size + x1] << std::endl;

  int ret = sumMap[y1 * size + x1];
  if (y0 != 0) {
    ret -= sumMap[(y0 - 1) * size + x1];
  }
  if (x0 != 0) {
    ret -= sumMap[(y1)*size + x0 - 1];
  }
  if (x0 != 0 && y0 != 0) {
    ret += sumMap[(y0 - 1) * size + x0 - 1];
  }
  return ret;
}
int main() {
  unsigned int size;
  int qCount;
  std::cin >> size;
  std::cin >> qCount;
  // std::cout << size << " " << qCount << std::endl;
  std::vector<int> forest(size * size, 0);
  std::vector<int> sumMap(size * size, 0);
  std::cin.get();
  for (int yy = 0; yy < size; yy++) {
    char ret;
    for (int xx = 0; xx < size; xx++) {
      std::cin.get(ret);
      // std::cout << (int)ret << " ";
      forest[yy * size + xx] = ret == '*' ? 1 : 0;
      if (yy == 0 && xx == 0) {
        sumMap[yy * size + xx] = ret == '*' ? 1 : 0;
      } else if (yy == 0) {
        sumMap[yy * size + xx] = sumMap[xx - 1] + forest[xx];
      } else if (xx == 0) {
        sumMap[yy * size + xx] = sumMap[(yy - 1) * size] + forest[yy * size];
      } else {
        sumMap[yy * size + xx] =
            sumMap[(yy - 1) * size + xx] + sumMap[yy * size + xx - 1] -
            sumMap[(yy - 1) * size + xx - 1] + forest[yy * size + xx];
      }
    }
    std::cin.get();
    // std::cout << std::endl;
  }
  // for (int yy = 0; yy < size; yy++) {
  //   for (int xx = 0; xx < size; xx++) {
  //     std::cout << sumMap[yy * size + xx] << " ";
  //   }
  //   std::cout << std::endl;
  // }
  for (int qq = 0; qq < qCount; qq++) {
    int x0, y0, x1, y1;
    std::cin >> y0;
    std::cin >> x0;
    std::cin >> y1;
    std::cin >> x1;
    int ret = getSubSum(x0 - 1, y0 - 1, x1 - 1, y1 - 1, sumMap, size);
    std::cout << ret << std::endl;
    // break;
  }
}

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