Submission #21593

# Submission time Handle Problem Language Result Execution time Memory
21593 2017-04-15T05:19:09 Z kingpig9 Cultivation (JOI17_cultivation) C++11
30 / 100
416 ms 7240 KB
#include <bits/stdc++.h>

using namespace std;
const int MAXN = 310, MAXS = 1e5 + 10;

void setmin (int &a, int b) {
	if (a > b) {
		a = b;
	}
}

void setmax (int &a, int b) {
	if (a < b) {
		a = b;
	}
}

int R, C, N;
int X[MAXN], Y[MAXN];
set<int> sty[MAXS];

int main() {
	//monica lewinsky
	scanf("%d %d %d", &R, &C, &N);
	for (int i = 1; i <= N; i++) {
		scanf("%d %d", &X[i], &Y[i]);
	}

	int ans = INT_MAX;
	for (int nup = 0; nup < R; nup++) {
		for (int i = 1; i <= R; i++) {
			sty[i].clear();
		}

		for (int i = 1; i <= N; i++) {
			for (int x = X[i]; x && x >= X[i] - nup; x--) {
				sty[x].insert(Y[i]);
			}
		}

		for (int ndown = 0; ndown < R; ndown++) {
			for (int i = 1; i <= N; i++) {
				int nx = ndown + X[i];
				if (nx <= R) {
					sty[nx].insert(Y[i]);
				}
			}

			//ok find the min difference
			bool bad = false;
			for (int i = 1; i <= R; i++) {
				if (sty[i].empty()) {
					bad = true;
					break;
				}
			}
			if (bad) {
				continue;
			}

			//left or right
			int nleft = 0, nright = 0;
			for (int i = 1; i <= R; i++) {
				setmax(nleft, *sty[i].begin()  - 1);
				setmax(nright, C - *sty[i].rbegin());
			}

			int nadd = 0;
			for (int i = 1; i <= R; i++) {
				for (auto it = sty[i].begin(); next(it) != sty[i].end(); it++) {
					int y1 = *it + nright, y2 = *next(it) - nleft;
					//how many are between those two
					setmax(nadd, y2 - y1 - 1);
				}
			}

			setmin(ans, nup + ndown + nleft + nright + nadd);
		}
	}

	printf("%d\n", ans);
}

Compilation message

cultivation.cpp: In function 'int main()':
cultivation.cpp:24:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &R, &C, &N);
                               ^
cultivation.cpp:26:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &X[i], &Y[i]);
                               ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6712 KB Output is correct
2 Correct 0 ms 6712 KB Output is correct
3 Correct 0 ms 6712 KB Output is correct
4 Correct 0 ms 6712 KB Output is correct
5 Correct 0 ms 6712 KB Output is correct
6 Correct 3 ms 6712 KB Output is correct
7 Correct 0 ms 6712 KB Output is correct
8 Correct 0 ms 6712 KB Output is correct
9 Correct 0 ms 6712 KB Output is correct
10 Correct 0 ms 6712 KB Output is correct
11 Correct 3 ms 6712 KB Output is correct
12 Correct 0 ms 6712 KB Output is correct
13 Correct 0 ms 6712 KB Output is correct
14 Correct 3 ms 6712 KB Output is correct
15 Correct 3 ms 6712 KB Output is correct
16 Correct 3 ms 6712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6712 KB Output is correct
2 Correct 0 ms 6712 KB Output is correct
3 Correct 0 ms 6712 KB Output is correct
4 Correct 0 ms 6712 KB Output is correct
5 Correct 0 ms 6712 KB Output is correct
6 Correct 3 ms 6712 KB Output is correct
7 Correct 0 ms 6712 KB Output is correct
8 Correct 0 ms 6712 KB Output is correct
9 Correct 0 ms 6712 KB Output is correct
10 Correct 0 ms 6712 KB Output is correct
11 Correct 3 ms 6712 KB Output is correct
12 Correct 0 ms 6712 KB Output is correct
13 Correct 0 ms 6712 KB Output is correct
14 Correct 3 ms 6712 KB Output is correct
15 Correct 3 ms 6712 KB Output is correct
16 Correct 3 ms 6712 KB Output is correct
17 Correct 3 ms 6712 KB Output is correct
18 Correct 9 ms 6712 KB Output is correct
19 Correct 13 ms 6712 KB Output is correct
20 Correct 0 ms 6712 KB Output is correct
21 Correct 16 ms 6712 KB Output is correct
22 Correct 33 ms 6844 KB Output is correct
23 Correct 6 ms 6712 KB Output is correct
24 Correct 53 ms 6844 KB Output is correct
25 Correct 33 ms 6844 KB Output is correct
26 Correct 49 ms 6844 KB Output is correct
27 Correct 49 ms 6844 KB Output is correct
28 Correct 39 ms 6844 KB Output is correct
29 Correct 46 ms 6844 KB Output is correct
30 Correct 46 ms 6844 KB Output is correct
31 Correct 46 ms 6844 KB Output is correct
32 Correct 49 ms 6844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6712 KB Output is correct
2 Correct 0 ms 6712 KB Output is correct
3 Correct 0 ms 6712 KB Output is correct
4 Correct 0 ms 6712 KB Output is correct
5 Correct 0 ms 6712 KB Output is correct
6 Correct 3 ms 6712 KB Output is correct
7 Correct 0 ms 6712 KB Output is correct
8 Correct 0 ms 6712 KB Output is correct
9 Correct 0 ms 6712 KB Output is correct
10 Correct 0 ms 6712 KB Output is correct
11 Correct 3 ms 6712 KB Output is correct
12 Correct 0 ms 6712 KB Output is correct
13 Correct 0 ms 6712 KB Output is correct
14 Correct 3 ms 6712 KB Output is correct
15 Correct 3 ms 6712 KB Output is correct
16 Correct 3 ms 6712 KB Output is correct
17 Correct 3 ms 6712 KB Output is correct
18 Correct 9 ms 6712 KB Output is correct
19 Correct 13 ms 6712 KB Output is correct
20 Correct 0 ms 6712 KB Output is correct
21 Correct 16 ms 6712 KB Output is correct
22 Correct 33 ms 6844 KB Output is correct
23 Correct 6 ms 6712 KB Output is correct
24 Correct 53 ms 6844 KB Output is correct
25 Correct 33 ms 6844 KB Output is correct
26 Correct 49 ms 6844 KB Output is correct
27 Correct 49 ms 6844 KB Output is correct
28 Correct 39 ms 6844 KB Output is correct
29 Correct 46 ms 6844 KB Output is correct
30 Correct 46 ms 6844 KB Output is correct
31 Correct 46 ms 6844 KB Output is correct
32 Correct 49 ms 6844 KB Output is correct
33 Correct 3 ms 6712 KB Output is correct
34 Correct 386 ms 7240 KB Output is correct
35 Correct 293 ms 7108 KB Output is correct
36 Correct 416 ms 7240 KB Output is correct
37 Correct 253 ms 7240 KB Output is correct
38 Correct 396 ms 7240 KB Output is correct
39 Correct 389 ms 7240 KB Output is correct
40 Correct 406 ms 7240 KB Output is correct
41 Correct 276 ms 7240 KB Output is correct
42 Correct 226 ms 7108 KB Output is correct
43 Correct 346 ms 7240 KB Output is correct
44 Correct 209 ms 7108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 6712 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 6712 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6712 KB Output is correct
2 Correct 0 ms 6712 KB Output is correct
3 Correct 0 ms 6712 KB Output is correct
4 Correct 0 ms 6712 KB Output is correct
5 Correct 0 ms 6712 KB Output is correct
6 Correct 3 ms 6712 KB Output is correct
7 Correct 0 ms 6712 KB Output is correct
8 Correct 0 ms 6712 KB Output is correct
9 Correct 0 ms 6712 KB Output is correct
10 Correct 0 ms 6712 KB Output is correct
11 Correct 3 ms 6712 KB Output is correct
12 Correct 0 ms 6712 KB Output is correct
13 Correct 0 ms 6712 KB Output is correct
14 Correct 3 ms 6712 KB Output is correct
15 Correct 3 ms 6712 KB Output is correct
16 Correct 3 ms 6712 KB Output is correct
17 Correct 3 ms 6712 KB Output is correct
18 Correct 9 ms 6712 KB Output is correct
19 Correct 13 ms 6712 KB Output is correct
20 Correct 0 ms 6712 KB Output is correct
21 Correct 16 ms 6712 KB Output is correct
22 Correct 33 ms 6844 KB Output is correct
23 Correct 6 ms 6712 KB Output is correct
24 Correct 53 ms 6844 KB Output is correct
25 Correct 33 ms 6844 KB Output is correct
26 Correct 49 ms 6844 KB Output is correct
27 Correct 49 ms 6844 KB Output is correct
28 Correct 39 ms 6844 KB Output is correct
29 Correct 46 ms 6844 KB Output is correct
30 Correct 46 ms 6844 KB Output is correct
31 Correct 46 ms 6844 KB Output is correct
32 Correct 49 ms 6844 KB Output is correct
33 Correct 3 ms 6712 KB Output is correct
34 Correct 386 ms 7240 KB Output is correct
35 Correct 293 ms 7108 KB Output is correct
36 Correct 416 ms 7240 KB Output is correct
37 Correct 253 ms 7240 KB Output is correct
38 Correct 396 ms 7240 KB Output is correct
39 Correct 389 ms 7240 KB Output is correct
40 Correct 406 ms 7240 KB Output is correct
41 Correct 276 ms 7240 KB Output is correct
42 Correct 226 ms 7108 KB Output is correct
43 Correct 346 ms 7240 KB Output is correct
44 Correct 209 ms 7108 KB Output is correct
45 Runtime error 0 ms 6712 KB Execution killed with signal 11 (could be triggered by violating memory limits)
46 Halted 0 ms 0 KB -