# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
476232 |
2021-09-25T13:27:44 Z |
rainboy |
Strah (COCI18_strah) |
C |
|
337 ms |
70704 KB |
#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 != m)
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]);
| ^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5836 KB |
Output is correct |
2 |
Correct |
6 ms |
5836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5836 KB |
Output is correct |
2 |
Correct |
6 ms |
5820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5836 KB |
Output is correct |
2 |
Correct |
6 ms |
5836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
25664 KB |
Output is correct |
2 |
Correct |
213 ms |
48184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
124 ms |
43756 KB |
Output is correct |
2 |
Incorrect |
337 ms |
63912 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
28076 KB |
Output is correct |
2 |
Correct |
238 ms |
51404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
29772 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
299 ms |
66692 KB |
Output is correct |
2 |
Correct |
200 ms |
70704 KB |
Output is correct |