CSES - Aalto Competitive Programming 2024 - wk4 - Mon - Results
Submission details
Task:Forest density
Sender:odanobunaga8199
Submission time:2024-09-23 17:22:57 +0300
Language:C++ (C++20)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.10 sdetails
#3ACCEPTED0.08 sdetails

Code

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, q;
    cin >> n >> q;

    vector<vector<int>> S(n + 1, vector<int>(n + 1, 0));

    for(int i = 1; i <= n; ++i){
        string row;
        cin >> row;
        for(int j = 1; j <= n; ++j){
            int tree = (row[j-1] == '*') ? 1 : 0;
            S[i][j] = S[i-1][j] + S[i][j-1] - S[i-1][j-1] + tree;
        }
    }

    string output = "";
    for(int q_num = 0; q_num < q; ++q_num){
        int y1, x1, y2, x2;
        cin >> y1 >> x1 >> y2 >> x2;
        int count = S[y2][x2] - S[y1 - 1][x2] - S[y2][x1 - 1] + S[y1 - 1][x1 - 1];
        output += to_string(count) + "\n";
    }

    cout << output;
}

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