Submission #392835

#TimeUsernameProblemLanguageResultExecution timeMemory
392835rainboyBob (COCI14_bob)C11
12 / 120
164 ms13876 KiB
#include <stdio.h> #define N 1000 #define M 1000 int main() { static int aa[N][M], ll[N], ii[N], pp[N], qq[N]; static char active[N]; int n, m, h, i, j, r, ans; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) for (j = 0; j < m; j++) scanf("%d", &aa[i][j]); ans = 0; for (r = 0; r < m; r++) { int i1, i2, cnt; i1 = 0, i2 = n; for (i = 0; i < n; i++) if (r == 0 || aa[i][r] != aa[i][r - 1]) ll[i] = r, ii[--i2] = i; else ii[i1++] = i; for (i = 0; i < n; i++) active[i] = 0, pp[i] = qq[i] = i; cnt = 0; for (h = 0; h < n; h++) { int p, q; i = ii[h]; active[i] = 1; p = i, q = i; if (i > 0 && active[i - 1] && aa[i][r] == aa[i - 1][r]) cnt -= (i - pp[i - 1]) * (i - pp[i - 1] + 1) / 2, p = pp[i - 1]; if (i + 1 < n && active[i + 1] && aa[i][r] == aa[i + 1][r]) cnt -= (qq[i + 1] - i) * (qq[i + 1] - i + 1) / 2, q = qq[i + 1]; cnt += (q - p + 1) * (q - p + 2) / 2; qq[p] = q, pp[q] = p; ans += ((h + 1 == n ? r + 1 : ll[ii[h + 1]]) - ll[ii[h]]) * cnt; } } printf("%d\n", ans); return 0; }

Compilation message (stderr)

bob.c: In function 'main':
bob.c:11:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   11 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
bob.c:14:4: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   14 |    scanf("%d", &aa[i][j]);
      |    ^~~~~~~~~~~~~~~~~~~~~~
#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...