Submission #392842

# Submission time Handle Problem Language Result Execution time Memory
392842 2021-04-21T21:47:51 Z rainboy Bob (COCI14_bob) C
120 / 120
195 ms 6148 KB
#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

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 time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 2212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 2132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 195 ms 4116 KB Output is correct
2 Correct 119 ms 6148 KB Output is correct
3 Correct 116 ms 6128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 166 ms 4164 KB Output is correct
2 Correct 120 ms 6072 KB Output is correct
3 Correct 115 ms 6068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 167 ms 4192 KB Output is correct
2 Correct 124 ms 6084 KB Output is correct
3 Correct 117 ms 6088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 165 ms 4188 KB Output is correct
2 Correct 123 ms 6148 KB Output is correct
3 Correct 117 ms 6132 KB Output is correct