Submission #683104

#TimeUsernameProblemLanguageResultExecution timeMemory
683104rainboyCultivation (JOI17_cultivation)C11
30 / 100
2071 ms332 KiB
#include <stdio.h>

#define N	40
#define M	300
#define INF	0x3f3f3f3f3f3f3f3fLL

long long min(long long a, long long b) { return a < b ? a : b; }
long long max(long long a, long long b) { return a > b ? a : b; }

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

void sort(int *aa, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, a = aa[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (aa[j] == a)
				j++;
			else if (aa[j] < a) {
				tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = aa[j], aa[j] = aa[k], aa[k] = tmp;
			}
		sort(aa, l, i);
		l = k;
	}
}

int main() {
	static int ii[M], jj[M], jj_[M];
	int n, m, k, k_, h, i, u, d;
	long long l, r, c, ans;

	scanf("%d%d%d", &n, &m, &k);
	for (h = 0; h < k; h++)
		scanf("%d%d", &ii[h], &jj[h]), ii[h]--, jj[h]--;
	ans = INF;
	for (u = 0; u < n; u++)
		for (d = 0; d < n; d++) {
			l = r = c = 0;
			for (i = 0; i < n; i++) {
				k_ = 0;
				for (h = 0; h < k; h++)
					if (ii[h] - u <= i && i <= ii[h] + d)
						jj_[k_++] = jj[h];
				if (k_ == 0) {
					c = INF;
					break;
				}
				sort(jj_, 0, k_);
				l = max(l, jj_[0] - 0), r = max(r, m - 1 - jj_[k_ - 1]);
				for (h = 1; h < k_; h++)
					c = max(c, jj_[h] - jj_[h - 1] - 1);
			}
			ans = min(ans, u + d + max(l + r, c));
		}
	printf("%lld\n", ans);
	return 0;
}

Compilation message (stderr)

cultivation.c: In function 'main':
cultivation.c:40:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  scanf("%d%d%d", &n, &m, &k);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
cultivation.c:42:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |   scanf("%d%d", &ii[h], &jj[h]), ii[h]--, jj[h]--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...