Submission #59862

# Submission time Handle Problem Language Result Execution time Memory
59862 2018-07-23T08:14:12 Z 윤교준(#1726) Cultivation (JOI17_cultivation) C++11
30 / 100
263 ms 1656 KB
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define sz(V) ((int)(V).size())
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;

const bool debug = 0;
const int MAXN = 305;

struct EVT {
	EVT(int type, int y, int x)
		: type(type), y(y), x(x) {}
	int type, y, x;

	bool operator < (const EVT &t) const {
		if(x != t.x) return x < t.x;
		if(type != t.type) return type > t.type;
		return y < t.y;
	}
};

vector<int> LV, RV;

int A[MAXN], B[MAXN], C[MAXN];

ll Ans = INFLL;
int H, W, N, LX, RX;

int main() {
	ios::sync_with_stdio(false);

	cin >> H >> W >> N;
	for(int i = 1; i <= N; i++) cin >> A[i] >> B[i];

	swap(H, W);
	for(int i = 1; i <= N; i++) swap(A[i], B[i]);

	LX = *min_element(B+1, B+N+1) - 1;
	RX = W - *max_element(B+1, B+N+1);

	for(int i = 1; i <= N; i++) {
		int s = max(1, B[i]-LX), e = min(W, B[i]+RX);
		B[i] = s; C[i] = e;
	}

	LV.eb(0); RV.eb(0);
	for(int i = 1; i <= N; i++) for(int j = 1; j <= N; j++) {
		int t = max(0, B[j]-C[i]-1);
		LV.eb(t); RV.eb(t);
	}
	for(int i = 1; i <= N; i++) LV.eb(B[i]-1);
	for(int i = 1; i <= N; i++) RV.eb(W-C[i]);
	sorv(LV); sorv(RV); univ(LV); univ(RV);

	if(debug) {
		for(int i = 1; i <= N; i++)
			printf("%d ; %d / %d %d\n", i, A[i], B[i], C[i]);
	}

	for(int l : LV) {
		RV.clear();
		RV.eb(0);
		for(int i = 1; i <= N; i++) RV.eb(W-C[i]);
		/*
		for(int i = 1; i <= N; i++) for(int j = 1; j <= N; j++) {
			int t = max(0, (max(1, B[j]-l) - C[i] - 1));
			RV.eb(t);
		}
		*/
		sorv(RV); univ(RV);
		for(int r : RV) {

			multiset<int> CH;
			vector<EVT> EV;

			for(int i = 1, s, e; i <= N; i++) {
				s = max(1, B[i]-l), e = min(W, C[i]+r);
				EV.eb(1, A[i], s);
				EV.eb(0, A[i], e+1);
			}
			sorv(EV);
			CH.insert(0); CH.insert(H+1);

			if(debug) {
				printf("l=%d, r=%d\n", l, r);
				for(auto &ev : EV) printf("%d %d %d\n", ev.type, ev.x, ev.y);
			}

			int upd = 0, dwd = 0, mxs = 0;

			for(int i = 0, j, n = sz(EV); i < n; i = j) {
				for(j = i; j < n && EV[i].x == EV[j].x; j++) {
					EVT &ev = EV[j];
					if(debug) printf("EVT %d ; %d %d\n", ev.type, ev.x, ev.y);
					if(W < ev.x) continue;
					if(ev.type) {
						CH.insert(ev.y);
						auto dit = prev(CH.lower_bound(ev.y));

						if(0 == *dit) upmax(dwd, ev.y - *dit - 1);
						else upmax(mxs, ev.y - *dit - 1);
					} else {
						CH.erase(CH.find(ev.y));
						if(CH.end() != CH.find(ev.y)) continue;

						auto dit = prev(CH.lower_bound(ev.y));
						auto uit = CH.upper_bound(ev.y);

						if(0 == *dit && H+1 == *uit) {
							upd = dwd = INF;
							continue;
						} else if(0 == *dit) upmax(dwd, *uit - *dit - 1);
						else if(H+1 == *uit) upmax(upd, *uit - *dit - 1);
						else upmax(mxs, *uit - *dit - 1);
					}
					if(debug) {
						for(int v : CH) printf("%d ", v);
						puts("");
						printf("upd=%d, dwd=%d, mxs=%d\n", upd, dwd, mxs);
					}
				}

				{
					auto it = prev(prev(CH.end()));
					if(0 == *it) upd = dwd = INF;
					else upmax(upd, H - *it);
				}
			}

			if(H <= upd || H <= dwd) continue;

			upmin(Ans, (ll)max(upd+dwd, mxs) + l + r);
		}
	}

	cout << (Ans + LX + RX) << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 436 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 3 ms 568 KB Output is correct
6 Correct 2 ms 568 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
8 Correct 2 ms 568 KB Output is correct
9 Correct 3 ms 568 KB Output is correct
10 Correct 2 ms 568 KB Output is correct
11 Correct 3 ms 612 KB Output is correct
12 Correct 2 ms 732 KB Output is correct
13 Correct 2 ms 732 KB Output is correct
14 Correct 2 ms 732 KB Output is correct
15 Correct 3 ms 732 KB Output is correct
16 Correct 2 ms 732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 436 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 3 ms 568 KB Output is correct
6 Correct 2 ms 568 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
8 Correct 2 ms 568 KB Output is correct
9 Correct 3 ms 568 KB Output is correct
10 Correct 2 ms 568 KB Output is correct
11 Correct 3 ms 612 KB Output is correct
12 Correct 2 ms 732 KB Output is correct
13 Correct 2 ms 732 KB Output is correct
14 Correct 2 ms 732 KB Output is correct
15 Correct 3 ms 732 KB Output is correct
16 Correct 2 ms 732 KB Output is correct
17 Correct 4 ms 732 KB Output is correct
18 Correct 19 ms 748 KB Output is correct
19 Correct 8 ms 748 KB Output is correct
20 Correct 5 ms 748 KB Output is correct
21 Correct 25 ms 748 KB Output is correct
22 Correct 84 ms 816 KB Output is correct
23 Correct 4 ms 816 KB Output is correct
24 Correct 130 ms 1128 KB Output is correct
25 Correct 93 ms 1128 KB Output is correct
26 Correct 227 ms 1636 KB Output is correct
27 Correct 210 ms 1640 KB Output is correct
28 Correct 123 ms 1640 KB Output is correct
29 Correct 201 ms 1640 KB Output is correct
30 Correct 226 ms 1640 KB Output is correct
31 Correct 206 ms 1644 KB Output is correct
32 Correct 218 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 436 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 3 ms 568 KB Output is correct
6 Correct 2 ms 568 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
8 Correct 2 ms 568 KB Output is correct
9 Correct 3 ms 568 KB Output is correct
10 Correct 2 ms 568 KB Output is correct
11 Correct 3 ms 612 KB Output is correct
12 Correct 2 ms 732 KB Output is correct
13 Correct 2 ms 732 KB Output is correct
14 Correct 2 ms 732 KB Output is correct
15 Correct 3 ms 732 KB Output is correct
16 Correct 2 ms 732 KB Output is correct
17 Correct 4 ms 732 KB Output is correct
18 Correct 19 ms 748 KB Output is correct
19 Correct 8 ms 748 KB Output is correct
20 Correct 5 ms 748 KB Output is correct
21 Correct 25 ms 748 KB Output is correct
22 Correct 84 ms 816 KB Output is correct
23 Correct 4 ms 816 KB Output is correct
24 Correct 130 ms 1128 KB Output is correct
25 Correct 93 ms 1128 KB Output is correct
26 Correct 227 ms 1636 KB Output is correct
27 Correct 210 ms 1640 KB Output is correct
28 Correct 123 ms 1640 KB Output is correct
29 Correct 201 ms 1640 KB Output is correct
30 Correct 226 ms 1640 KB Output is correct
31 Correct 206 ms 1644 KB Output is correct
32 Correct 218 ms 1644 KB Output is correct
33 Correct 9 ms 1652 KB Output is correct
34 Correct 166 ms 1652 KB Output is correct
35 Correct 249 ms 1652 KB Output is correct
36 Correct 263 ms 1652 KB Output is correct
37 Correct 193 ms 1652 KB Output is correct
38 Correct 254 ms 1652 KB Output is correct
39 Correct 243 ms 1652 KB Output is correct
40 Correct 249 ms 1656 KB Output is correct
41 Correct 133 ms 1656 KB Output is correct
42 Correct 231 ms 1656 KB Output is correct
43 Correct 249 ms 1656 KB Output is correct
44 Correct 249 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1656 KB Output is correct
2 Correct 52 ms 1656 KB Output is correct
3 Correct 42 ms 1656 KB Output is correct
4 Correct 39 ms 1656 KB Output is correct
5 Correct 49 ms 1656 KB Output is correct
6 Incorrect 19 ms 1656 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1656 KB Output is correct
2 Correct 52 ms 1656 KB Output is correct
3 Correct 42 ms 1656 KB Output is correct
4 Correct 39 ms 1656 KB Output is correct
5 Correct 49 ms 1656 KB Output is correct
6 Incorrect 19 ms 1656 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 436 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 3 ms 568 KB Output is correct
6 Correct 2 ms 568 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
8 Correct 2 ms 568 KB Output is correct
9 Correct 3 ms 568 KB Output is correct
10 Correct 2 ms 568 KB Output is correct
11 Correct 3 ms 612 KB Output is correct
12 Correct 2 ms 732 KB Output is correct
13 Correct 2 ms 732 KB Output is correct
14 Correct 2 ms 732 KB Output is correct
15 Correct 3 ms 732 KB Output is correct
16 Correct 2 ms 732 KB Output is correct
17 Correct 4 ms 732 KB Output is correct
18 Correct 19 ms 748 KB Output is correct
19 Correct 8 ms 748 KB Output is correct
20 Correct 5 ms 748 KB Output is correct
21 Correct 25 ms 748 KB Output is correct
22 Correct 84 ms 816 KB Output is correct
23 Correct 4 ms 816 KB Output is correct
24 Correct 130 ms 1128 KB Output is correct
25 Correct 93 ms 1128 KB Output is correct
26 Correct 227 ms 1636 KB Output is correct
27 Correct 210 ms 1640 KB Output is correct
28 Correct 123 ms 1640 KB Output is correct
29 Correct 201 ms 1640 KB Output is correct
30 Correct 226 ms 1640 KB Output is correct
31 Correct 206 ms 1644 KB Output is correct
32 Correct 218 ms 1644 KB Output is correct
33 Correct 9 ms 1652 KB Output is correct
34 Correct 166 ms 1652 KB Output is correct
35 Correct 249 ms 1652 KB Output is correct
36 Correct 263 ms 1652 KB Output is correct
37 Correct 193 ms 1652 KB Output is correct
38 Correct 254 ms 1652 KB Output is correct
39 Correct 243 ms 1652 KB Output is correct
40 Correct 249 ms 1656 KB Output is correct
41 Correct 133 ms 1656 KB Output is correct
42 Correct 231 ms 1656 KB Output is correct
43 Correct 249 ms 1656 KB Output is correct
44 Correct 249 ms 1656 KB Output is correct
45 Correct 14 ms 1656 KB Output is correct
46 Correct 52 ms 1656 KB Output is correct
47 Correct 42 ms 1656 KB Output is correct
48 Correct 39 ms 1656 KB Output is correct
49 Correct 49 ms 1656 KB Output is correct
50 Incorrect 19 ms 1656 KB Output isn't correct
51 Halted 0 ms 0 KB -