Submission #392841

# Submission time Handle Problem Language Result Execution time Memory
392841 2021-04-21T21:45:19 Z rainboy Bob (COCI14_bob) C
12 / 120
171 ms 4188 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 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

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 Incorrect 1 ms 460 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 2256 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 2184 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 2180 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 2224 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 171 ms 4152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 166 ms 4124 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 164 ms 4164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 169 ms 4188 KB Output isn't correct
2 Halted 0 ms 0 KB -