# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
199522 | ZwariowanyMarcin | Strah (COCI18_strah) | C++14 | 196 ms | 20104 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define LL long long
#define LD long double
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, j, n) for(int i = j; i <= n; ++i)
#define boost cin.tie(0), ios_base::sync_with_stdio(0);
using namespace std;
const int nax = 2011;
int n, m;
char s[nax][nax];
int up[nax][nax];
LL ans;
LL tyt[nax];
LL f(int x) {
return (LL) x * (x + 1) / 2;
}
int L[nax];
int R[nax];
vector <int> v;
int main() {
scanf ("%d %d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf ("%s", s[i] + 1);
for (int j = 1; j <= m; ++j) {
if (s[i][j] == '#') up[i][j] = 0;
else up[i][j] = up[i - 1][j] + 1;
}
}
for (int i = 1; i <= m; ++i) {
LL res = 0;
for (int j = 1; j <= i; ++j)
res += j * (i - j + 1);
tyt[i] = res;
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m + 1; ++j) {
while (ss(v) && up[i][v.back()] > up[i][j]) {
R[v.back()] = j - 1;
v.pop_back();
}
if (j != m + 1) v.pb(j);
}
for (int j = m; 0 <= j; --j) {
while (ss(v) && up[i][v.back()] >= up[i][j]) {
L[v.back()] = j + 1;
v.pop_back();
}
if (j != 0) v.pb(j);
}
for (int j = 1; j <= m; ++j) {
if (!up[i][j]) continue;
int h = max(up[i][L[j] - 1], up[i][R[j] + 1]);
LL gao = (LL) (f(up[i][j]) - f(h)) * tyt[R[j] - L[j] + 1];
ans += gao;
}
}
printf ("%lld", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |