Submission #727918

# Submission time Handle Problem Language Result Execution time Memory
727918 2023-04-21T14:54:11 Z rainboy Orchard (NOI14_orchard) C
25 / 25
173 ms 6108 KB
#include <stdio.h>

#define NM	1000000

int min(int a, int b) { return a < b ? a : b; }

int main() {
	static int aa[NM];
	int n, m, i, i1, i2, j, k, sum, ans;

	scanf("%d%d", &n, &m);
	k = 0;
	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++) {
			int a;

			scanf("%d", &a);
			if (a == 1)
				aa[i * m + j] = -1, k++;
			else
				aa[i * m + j] = 1;
		}
	for (j = 0; j < m; j++)
		for (i = 1; i < n; i++)
			aa[i * m + j] += aa[(i - 1) * m + j];
	ans = n * m;
	for (i1 = 0; i1 < n; i1++)
		for (i2 = i1; i2 < n; i2++) {
			sum = 0;
			for (j = 0; j < m; j++) {
				sum = min(sum + aa[i2 * m + j] - (i1 == 0 ? 0 : aa[(i1 - 1) * m + j]), 0);
				ans = min(ans, k + sum);
			}
		}
	printf("%d\n", ans);
	return 0;
}

Compilation message

orchard.c: In function 'main':
orchard.c:11:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
orchard.c:17:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |    scanf("%d", &a);
      |    ^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 316 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 6108 KB Output is correct
2 Correct 91 ms 6024 KB Output is correct
3 Correct 89 ms 6092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1356 KB Output is correct
2 Correct 19 ms 1364 KB Output is correct
3 Correct 19 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 6 ms 340 KB Output is correct
3 Correct 6 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 172 ms 4648 KB Output is correct
2 Correct 170 ms 4556 KB Output is correct
3 Correct 173 ms 4680 KB Output is correct