| Task: | Forest density |
| Sender: | discape |
| Submission time: | 2025-09-22 17:34:13 +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 |
Code
#include <bits/stdc++.h>
using namespace std;
// clang-format off
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { T value; is >> value; v.push_back(value); return is; }
#define preamble ios::sync_with_stdio(0); cin.tie(0); dbg("INIT");
// clang-format on
#ifdef DO_DBG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
template <typename T> using v = vector<T>;
template <typename T> using us = unordered_set<T>;
template <typename K, typename V> using um = unordered_map<K, V>;
constexpr int MOD = 1e9 + 7;
const int INF = 1e9;
const ld EPS = 1e-9;
#define loopi(n) for (int i = 0; i < n; i++)
#define loopj(n) for (int j = 0; j < n; j++)
#define loopk(n) for (int k = 0; k < n; k++)
#define loopz(n) for (int z = 0; z < n; z++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sq(x) ((x) * (x))
int main() {
int n, q;
cin >> n >> q;
v<bool> forest(n * n);
v<int> prefix(n * n);
loopi(n) {
loopj(n) {
char c;
cin >> c;
int res = c == '*' ? 1 : 0;
// forest[i * n + j] = res;
int sum = res;
if (i != 0) {
sum += prefix[(i - 1) * n + j];
}
if (j != 0) {
sum += prefix[i * n + j - 1];
}
if (j != 0 && i != 0) {
sum -= prefix[(i - 1) * n + (j - 1)];
}
prefix[i * n + j] = sum;
cerr << sum << " ";
}
cerr << "\n";
}
loopi(q) {
int y1, x1, y2, x2;
cin >> y1 >> x1 >> y2 >> x2;
y2--;
x2--;
y1--;
y1--;
x1--;
x1--;
int a = y2 >= 0 && x2 >= 0 ? prefix[y2 * n + x2] : 0;
int b = y2 >= 0 && x1 >= 0 ? prefix[y2 * n + x1] : 0;
int c = y1 >= 0 && x2 >= 0 ? prefix[y1 * n + x2] : 0;
int d = y1 >= 0 && x1 >= 0 ? prefix[y1 * n + x1] : 0;
dbg(a, b, c, d);
int sum = a - b - c + d;
cout << sum << "\n";
}
dbg(prefix);
}
Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 10 100 **.*.*.**. *.**.*..*. .*****.**. **....***. ... |
| correct output |
|---|
| 10 14 5 7 8 ... |
| user output |
|---|
| 10 14 5 7 8 ... Truncated |
Error:
1 2 2 3 3 4 4 5 6 6 2 3 4 6 6 8 8 9 11 11 2 4 6 9 10 13 13 15 18 18 3 6 8 11 12 15 16 1...
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) |
