CSES - Aalto Competitive Programming 2024 - wk4 - Mon - Results
Submission details
Task:Forest density
Sender:Rasse
Submission time:2024-09-23 16:37:05 +0300
Language:C++ (C++11)
Status:READY
Result:
Test results
testverdicttime
#10.00 sdetails
#20.53 sdetails
#30.51 sdetails

Code

// Online C++ compiler to run C++ program online
#include <iostream>
#include <vector>
#include <climits>
 
using namespace std;
 
int main() {
    int n, q;
    cin >> n >> q;
    
    vector<vector<int>> trees(n+1, vector<int>(n+1, 0));
    
    for (int y = 0; y < n; y++)
    {
        string s;
        cin >> s;
        for (int x = 0; x < n; x++)
        {
            trees[y+1][x+1] = (s[x] == '*') + trees[y][x+1] + trees[y+1][x];
        }
    }
    
    for (int i = 0; i < q; i++)
    {
        int y1, x1, y2, x2;
        cin >> y1 >> x1 >> y2 >> x2;
        
        int res = trees[y2][x2] - trees[y1-1][x2] - trees[y2][x1-1] + trees[y1-1][x1-1];
        cout << res << endl;
    }
    
    
 
    return 0;
}

Test details

Test 1

Verdict:

input
10 100
**.*.*.**.
*.**.*..*.
.*****.**.
**....***.
...

correct output
10
14
5
7
8
...

user output
3019
16013
8572
1554
1555
...
Truncated

Test 2

Verdict:

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

correct output
41079
2824
15631
1548
8483
...

user output
311426075
1697724053
-1031205864
-1671017811
-1535895631
...
Truncated

Test 3

Verdict:

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

correct output
1000000
1000000
1000000
1000000
1000000
...

user output
-531600833
-531600833
-531600833
-531600833
-531600833
...
Truncated