#include <stdio.h>
#include <string.h>
#define N 2000
#define M 2000
int main() {
static char cc[N][M + 1];
static int kk[N][M], pp[N][M], qq[N][M], hh[N * M], cnt[M + 2];
int n, m, h, i, j, k;
long long ans, x;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++)
scanf("%s", cc[i]);
for (i = 0; i < n; i++)
for (j = m - 1, k = 0; j >= 0; j--)
kk[i][j] = k = cc[i][j] == '#' ? 0 : k + 1;
memset(cnt, 0, (m + 2) * sizeof *cnt);
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
cnt[kk[i][j] + 1]++;
for (k = 1; k <= m + 1; k++)
cnt[k] += cnt[k - 1];
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
hh[cnt[kk[i][j]]++] = i * m + j;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
pp[i][j] = i - 1, qq[i][j] = i + 1;
x = 0;
ans = 0;
for (k = m, h = n * m - 1; k >= 1; k--) {
while (h >= 0 && kk[hh[h] / m][hh[h] % m] == k) {
int p, q;
i = hh[h] / m, j = hh[h] % m, p = pp[i][j], q = qq[i][j];
x -= (long long) (i - p + 1) * (i - p) * (i - p - 1) / 6;
x -= (long long) (q - i + 1) * (q - i) * (q - i - 1) / 6;
x += (long long) (q - p + 1) * (q - p) * (q - p - 1) / 6;
if (p != -1)
qq[p][j] = q;
if (q != n)
pp[q][j] = p;
h--;
}
ans += x * k;
}
printf("%lld\n", ans);
return 0;
}
Compilation message
strah.c: In function 'main':
strah.c:13:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d%d", &n, &m);
| ^~~~~~~~~~~~~~~~~~~~~
strah.c:15:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | scanf("%s", cc[i]);
| ^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5844 KB |
Output is correct |
2 |
Correct |
6 ms |
5836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5836 KB |
Output is correct |
2 |
Correct |
6 ms |
5836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5836 KB |
Output is correct |
2 |
Correct |
6 ms |
5912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
25580 KB |
Output is correct |
2 |
Correct |
207 ms |
48224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
43744 KB |
Output is correct |
2 |
Correct |
317 ms |
63904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
106 ms |
28064 KB |
Output is correct |
2 |
Correct |
225 ms |
51504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
29748 KB |
Output is correct |
2 |
Correct |
205 ms |
62444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
313 ms |
66768 KB |
Output is correct |
2 |
Correct |
206 ms |
66800 KB |
Output is correct |