Submission #476231

#TimeUsernameProblemLanguageResultExecution timeMemory
476231rainboyStrah (COCI18_strah)C11
66 / 110
1076 ms70760 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...