# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
92698 | Kastanda | Strah (COCI18_strah) | C++11 | 113 ms | 24156 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>
using namespace std;
const int N = 2009;
int n, m, dn[N][N], P[N];
long long tot, sum, dp[N];
char A[N][N];
vector < int > Q[N];
int Find(int v)
{
return ((P[v] > 0) ? (P[v] = Find(P[v])) : v);
}
inline void Merge(int v, int u)
{
v = Find(v);
u = Find(u);
if (v == u)
return ;
sum -= dp[-P[v]];
sum -= dp[-P[u]];
P[v] += P[u];
P[u] = v;
sum += dp[-P[v]];
}
int main()
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%s", &A[i][1]);
for (int i = n; i; i--)
for (int j = 1; j <= m; j++)
{
dn[i][j] = dn[i + 1][j];
if (A[i][j] == '#')
dn[i][j] = i;
else if (i == n)
dn[i][j] = i + 1;
}
for (int i = 1; i < N; i++)
for (int j = 1; j <= i; j++)
dp[i] += (i - j + 1) * j;
for (int i = 1; i <= n; i++)
{
sum = 0;
memset(P, 0, sizeof(P));
for (int j = 1; j <= m; j++)
Q[dn[i][j] - 1].push_back(j);
for (int j = n; j >= i; j--)
{
for (int &id : Q[j])
{
P[id] = -1;
sum += dp[1];
if (P[id - 1])
Merge(id, id - 1);
if (P[id + 1])
Merge(id, id + 1);
}
tot += 1ll * sum * (j - i + 1);
}
for (int j = 0; j <= n; j++)
Q[j].clear();
}
return !printf("%lld", tot);
}
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... |