Submission #392842

#TimeUsernameProblemLanguageResultExecution timeMemory
392842rainboyBob (COCI14_bob)C11
120 / 120
195 ms6148 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 tmp, cnt; for (i = 0, j = 0; j < n; j++) if (r > 0 && aa[ii[j]][r] != aa[ii[j]][r - 1]) ll[ii[j]] = r; else tmp = ii[j], ii[j] = ii[i], ii[i] = tmp, 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("%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...