| Task: | Forest density |
| Sender: | aalto26dm_025 |
| Submission time: | 2026-09-21 17:47:06 +0300 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | TIME LIMIT EXCEEDED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | TIME LIMIT EXCEEDED | -- | details |
| #3 | TIME LIMIT EXCEEDED | -- | details |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:44:9: warning: unused variable 'full_array_size' [-Wunused-variable]
44 | int full_array_size = 2 * base_array_size;
| ^~~~~~~~~~~~~~~Code
#include <iostream>
#include <vector>
#include <cmath>
#include <bits/stdc++.h>
using namespace std;
int sum_in_area(int y1, int x1, int y2, int x2, vector<vector<int>> forest)
{
int sum = 0;
sum += forest[x2][y2];
sum -= forest[x1 - 1][y2];
sum -= forest[x2][y1 - 1];
sum += forest[x1 - 1][y1 - 1];
return sum;
}
inline void construct(const int &end, const int &line, const int &value, vector<vector<int>> & forest)
{
if(line != 0 && end !=0) forest[line][end] = value + forest[line - 1][end] + forest[line][end - 1] - forest[line - 1][end - 1];
else if(line == 0) forest[line][end] = value + forest[line][end - 1];
else if(end == 0) forest[line][end] = value + forest[line - 1][end];
else forest[line][end] = value;
}
void add(int k, int x, vector<int> & tree)
{
int n = tree.size() / 2;
k += n;
tree[k] = x;
for (k /= 2; k >= 1; k /= 2)
{
tree[k] = tree[2*k] + tree[2*k+1];
}
}
int main()
{
int forest_size, n_queries;
cin >> forest_size >> n_queries;
int base_array_size = pow(2, ceil(log2(forest_size)));
int full_array_size = 2 * base_array_size;
vector<vector<int>> forest(forest_size + 1, vector<int>(forest_size + 1, 0));
for(int l = 1; l < forest_size + 1; ++l)
{
string temp;
cin >> temp;
for(int c = 1; c < forest_size + 1; ++c)
{
if(temp[c - 1] == '.') construct(c, l, 0, forest);
if(temp[c - 1] == '*') construct(c, l, 1, forest);
}
}
for(int i = 0; i < n_queries; ++i)
{
int y1, x1, y2, x2;
cin >> y1 >> x1 >> y2 >> x2;
cout << sum_in_area(x1, y1, x2, y2, forest) << endl;
}
}Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 10 100 **.*.*.**. *.**.*..*. .*****.**. **....***. ... |
| correct output |
|---|
| 10 14 5 7 8 ... |
| user output |
|---|
| 10 14 5 7 8 ... |
Test 2
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 1000 200000 **.**.****..**.***..**.***.**.... |
| correct output |
|---|
| 41079 2824 15631 1548 8483 ... |
| user output |
|---|
| (empty) |
Test 3
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 1000 200000 ******************************... |
| correct output |
|---|
| 1000000 1000000 1000000 1000000 1000000 ... |
| user output |
|---|
| (empty) |
