Submission #392841

#TimeUsernameProblemLanguageResultExecution timeMemory
392841rainboyBob (COCI14_bob)C11
12 / 120
171 ms4188 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; long long ans; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) for (j = 0; j < m; j++) scanf("%d", &aa[i][j]); for (i = 0; i < n; i++) ii[i] = i; ans = 0; for (r = 0; r < m; r++) { int i1, i2, tmp, cnt; i1 = 0, i2 = n; while (i1 < i2) if (r == 0 || aa[ii[i1]][r] == aa[ii[i1]][r - 1]) i1++; else { ll[ii[i1]] = r; i2--; tmp = ii[i1], ii[i1] = ii[i2], ii[i2] = tmp; } 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("%lld\n", ans); return 0; }

Compilation message (stderr)

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