# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
476231 |
2021-09-25T13:25:15 Z |
rainboy |
Strah (COCI18_strah) |
C |
|
1000 ms |
70760 KB |
#include <stdio.h>
#define N 2000
#define M 2000
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int kk[N][M], n, m;
void sort(int *hh, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, h = hh[l + rand_() % (r - l)], tmp;
while (j < k) {
int c = kk[hh[j] / m][hh[j] % m] - kk[h / m][h % m];
if (c == 0)
j++;
else if (c < 0) {
tmp = hh[i], hh[i] = hh[j], hh[j] = tmp;
i++, j++;
} else {
k--;
tmp = hh[j], hh[j] = hh[k], hh[k] = tmp;
}
}
sort(hh, l, i);
l = k;
}
}
int main() {
static char cc[N][M + 1];
static int hh[N * M], pp[N][M], qq[N][M];
int 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;
for (h = 0; h < n * m; h++)
hh[h] = h;
sort(hh, 0, n * m);
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:42:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d%d", &n, &m);
| ^~~~~~~~~~~~~~~~~~~~~
strah.c:44:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%s", cc[i]);
| ^~~~~~~~~~~~~~~~~~
# |
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 |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
5936 KB |
Output is correct |
2 |
Correct |
14 ms |
5960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
5864 KB |
Output is correct |
2 |
Correct |
15 ms |
5824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
5932 KB |
Output is correct |
2 |
Correct |
15 ms |
5836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
131 ms |
26652 KB |
Output is correct |
2 |
Correct |
482 ms |
50564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
305 ms |
46160 KB |
Output is correct |
2 |
Incorrect |
777 ms |
67484 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
339 ms |
29672 KB |
Output is correct |
2 |
Correct |
555 ms |
53976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
29716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1076 ms |
70760 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |