CSES - Aalto Competitive Programming 2024 - wk4 - Mon - Results
Submission details
Task:Forest density
Sender:aarol
Submission time:2024-09-23 17:38:26 +0300
Language:C++ (C++11)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2--details
#3--details

Code

#include <bits/stdc++.h>

using namespace std;

int n;

int main() {
  // ios::sync_with_stdio(false);
  // cin.tie(0);
  int q;
  cin >> n >> q;

  auto values = vector<string>(n, "");

  auto sumarr = vector<vector<int>>(n, vector<int>(n));

  for (int i = 0; i < n; i++) {
    cin >> values[i];
  }

  for (int i = 0; i < n; i++) {
    for (int y = 0; y < n; y++) {
      int c = 0;

      for (int x = 0; x <= i; x++) {
        for (int yy = 0; yy <= y; yy++) {
          if (values[x][yy] == '*') c++;
        }
      }
      sumarr[i][y] = c;
    }
  }

  for (int i = 0; i < q; i++) {
    int y1, x1, y2, x2;
    cin >> y1 >> x1 >> y2 >> x2;
    y1--;
    x1--;
    y2--;
    x2--;
    int A = sumarr[y2][x2];
    if (x1 > 0) A -= sumarr[y2][x1 - 1];
    if (y1 > 0) A -= sumarr[y1 - 1][x2];
    if (y1 > 0 && x1 > 0) A += sumarr[y1 - 1][x1 - 1];

    cout << A << endl;
  }

  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
...
Truncated

Test 2

Verdict:

input
1000 200000
**.**.****..**.***..**.***.**....

correct output
41079
2824
15631
1548
8483
...

user output
(empty)

Test 3

Verdict:

input
1000 200000
******************************...

correct output
1000000
1000000
1000000
1000000
1000000
...

user output
(empty)