CSES - Aalto Competitive Programming 2024 - wk4 - Mon - Results
Submission details
Task:Forest density
Sender:MallocManfred
Submission time:2024-09-23 16:42:41 +0300
Language:C++ (C++20)
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.88 sdetails
#3ACCEPTED0.87 sdetails

Code

#include <bits/stdc++.h>

using namespace std;

signed main() {
    
    int n, q; // forest size, query number
    cin >> n >> q;
    
    int forest[n+1][n+1];
    
    // get input && calc prefix sum
    for (int i = 1; i <= n; i++) {

        for (int j = 1; j <= n; j++) {
            char input;
            cin >> input;
            if (input == '.') forest[i][j] = forest[i][j-1];
            else forest[i][j] = forest[i][j-1] + 1;
        }
    }

    // handle queries
    for (int i = 0; i < q; i++) {
        int x1, x2, y1, y2;
        cin >> y1 >> x1 >> y2 >> x2;

        int num_rows = y2 - y1; 
        int sum = 0;
        for (int j = 0; j <= num_rows; j++) {
            sum += forest[y1+j][x2] - forest[y1+j][x1-1]; 
        }
        cout << sum << "\n";
    }

    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: 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