Submission #392835

# Submission time Handle Problem Language Result Execution time Memory
392835 2021-04-21T21:33:58 Z rainboy Bob (COCI14_bob) C
12 / 120
164 ms 13876 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, 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

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 time Memory Grader output
1 Incorrect 1 ms 460 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 2832 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 3092 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 3396 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 3360 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 152 ms 10808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 164 ms 13876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 163 ms 13768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 163 ms 13840 KB Output isn't correct
2 Halted 0 ms 0 KB -