답안 #801558

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
801558 2023-08-02T06:36:28 Z GEN 이지후(#10129) Cultivation (JOI17_cultivation) C++17
60 / 100
2000 ms 12972 KB
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = array<lint, 2>;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()

map<pi, lint> mp;
lint solve(lint r, lint c, lint dl, lint dr, vector<pi> a) {
	if (mp.count({dl, dr}))
		return mp[pi{dl, dr}];
	vector<array<lint, 3>> event;
	for (auto &[x, y] : a) {
		int l = max(0ll, x - dl);
		int e = min(r * 1ll, x + 1 + dr);
		event.push_back({l, y, +1});
		event.push_back({e, y, -1});
	}
	sort(all(event));
	if (event[0][0] != 0 || event.back()[0] != r)
		return mp[pi{dl, dr}] = 1e18;
	lint lmax = 0, rmax = 0, lrmax = 0;
	multiset<lint> s;
	for (int i = 0; i < sz(event);) {
		int j = i;
		while (j < sz(event) && event[i][0] == event[j][0]) {
			if (event[j][2] == +1)
				s.insert(event[j][1]);
			else
				s.erase(s.find(event[j][1]));
			j++;
		}
		if (j == sz(event))
			break;
		if (sz(s) == 0)
			return mp[pi{dl, dr}] = 1e18;
		lmax = max(lmax, *s.begin());
		rmax = max(rmax, c - 1 - *s.rbegin());
		{
			auto it = s.begin();
			while (next(it) != s.end()) {
				lrmax = max(lrmax, *next(it) - *it - 1);
				it++;
			}
		}
		i = j;
	}
	return mp[pi{dl, dr}] = max(lmax + rmax, lrmax);
}

// n^6

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, r, c;
	cin >> r >> c >> n;
	vector<pi> a(n);
	for (auto &[x, y] : a)
		cin >> x >> y, x--, y--;
	sort(all(a));
	lint ans = 1e18;
	vector<lint> gaps = {0};
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (a[j][0] > a[i][0])
				gaps.push_back(a[j][0] - a[i][0] - 1);
		}
	}
	sort(all(gaps));
	gaps.resize(unique(all(gaps)) - gaps.begin());
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			ans = min(ans, a[i][0] + r - 1 - a[j][0] + solve(r, c, a[i][0], r - 1 - a[j][0], a));
		}
	}
	for (int i = 0; i < n; i++) {
		for (auto &dy : gaps) {
			if (a[i][0] <= dy)
				ans = min(ans, dy + solve(r, c, a[i][0], dy - a[i][0], a));
			if (r - 1 - a[i][0] <= dy)
				ans = min(ans, dy + solve(r, c, dy - (r - 1 - a[i][0]), r - 1 - a[i][0], a));
		}
	}
	cout << ans << endl;
}
# 결과 실행 시간 메모리 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
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 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
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 16 ms 596 KB Output is correct
19 Correct 5 ms 360 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 23 ms 364 KB Output is correct
22 Correct 77 ms 1456 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 149 ms 724 KB Output is correct
25 Correct 104 ms 524 KB Output is correct
26 Correct 243 ms 984 KB Output is correct
27 Correct 243 ms 984 KB Output is correct
28 Correct 135 ms 600 KB Output is correct
29 Correct 219 ms 856 KB Output is correct
30 Correct 254 ms 956 KB Output is correct
31 Correct 261 ms 984 KB Output is correct
32 Correct 253 ms 856 KB Output is correct
# 결과 실행 시간 메모리 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
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 16 ms 596 KB Output is correct
19 Correct 5 ms 360 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 23 ms 364 KB Output is correct
22 Correct 77 ms 1456 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 149 ms 724 KB Output is correct
25 Correct 104 ms 524 KB Output is correct
26 Correct 243 ms 984 KB Output is correct
27 Correct 243 ms 984 KB Output is correct
28 Correct 135 ms 600 KB Output is correct
29 Correct 219 ms 856 KB Output is correct
30 Correct 254 ms 956 KB Output is correct
31 Correct 261 ms 984 KB Output is correct
32 Correct 253 ms 856 KB Output is correct
33 Correct 10 ms 724 KB Output is correct
34 Correct 187 ms 984 KB Output is correct
35 Correct 238 ms 856 KB Output is correct
36 Correct 239 ms 984 KB Output is correct
37 Correct 173 ms 856 KB Output is correct
38 Correct 234 ms 984 KB Output is correct
39 Correct 229 ms 856 KB Output is correct
40 Correct 242 ms 984 KB Output is correct
41 Correct 95 ms 672 KB Output is correct
42 Correct 177 ms 984 KB Output is correct
43 Correct 230 ms 984 KB Output is correct
44 Correct 252 ms 984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 340 KB Output is correct
2 Correct 33 ms 552 KB Output is correct
3 Correct 35 ms 660 KB Output is correct
4 Correct 28 ms 472 KB Output is correct
5 Correct 35 ms 560 KB Output is correct
6 Correct 23 ms 428 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 19 ms 468 KB Output is correct
9 Correct 23 ms 452 KB Output is correct
10 Correct 39 ms 596 KB Output is correct
11 Correct 32 ms 604 KB Output is correct
12 Correct 32 ms 632 KB Output is correct
13 Correct 5 ms 340 KB Output is correct
14 Correct 14 ms 360 KB Output is correct
15 Correct 4 ms 332 KB Output is correct
16 Correct 35 ms 552 KB Output is correct
17 Correct 36 ms 648 KB Output is correct
18 Correct 5 ms 340 KB Output is correct
19 Correct 37 ms 588 KB Output is correct
20 Correct 22 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 340 KB Output is correct
2 Correct 33 ms 552 KB Output is correct
3 Correct 35 ms 660 KB Output is correct
4 Correct 28 ms 472 KB Output is correct
5 Correct 35 ms 560 KB Output is correct
6 Correct 23 ms 428 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 19 ms 468 KB Output is correct
9 Correct 23 ms 452 KB Output is correct
10 Correct 39 ms 596 KB Output is correct
11 Correct 32 ms 604 KB Output is correct
12 Correct 32 ms 632 KB Output is correct
13 Correct 5 ms 340 KB Output is correct
14 Correct 14 ms 360 KB Output is correct
15 Correct 4 ms 332 KB Output is correct
16 Correct 35 ms 552 KB Output is correct
17 Correct 36 ms 648 KB Output is correct
18 Correct 5 ms 340 KB Output is correct
19 Correct 37 ms 588 KB Output is correct
20 Correct 22 ms 508 KB Output is correct
21 Execution timed out 2041 ms 12972 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 16 ms 596 KB Output is correct
19 Correct 5 ms 360 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 23 ms 364 KB Output is correct
22 Correct 77 ms 1456 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 149 ms 724 KB Output is correct
25 Correct 104 ms 524 KB Output is correct
26 Correct 243 ms 984 KB Output is correct
27 Correct 243 ms 984 KB Output is correct
28 Correct 135 ms 600 KB Output is correct
29 Correct 219 ms 856 KB Output is correct
30 Correct 254 ms 956 KB Output is correct
31 Correct 261 ms 984 KB Output is correct
32 Correct 253 ms 856 KB Output is correct
33 Correct 10 ms 724 KB Output is correct
34 Correct 187 ms 984 KB Output is correct
35 Correct 238 ms 856 KB Output is correct
36 Correct 239 ms 984 KB Output is correct
37 Correct 173 ms 856 KB Output is correct
38 Correct 234 ms 984 KB Output is correct
39 Correct 229 ms 856 KB Output is correct
40 Correct 242 ms 984 KB Output is correct
41 Correct 95 ms 672 KB Output is correct
42 Correct 177 ms 984 KB Output is correct
43 Correct 230 ms 984 KB Output is correct
44 Correct 252 ms 984 KB Output is correct
45 Correct 7 ms 340 KB Output is correct
46 Correct 33 ms 552 KB Output is correct
47 Correct 35 ms 660 KB Output is correct
48 Correct 28 ms 472 KB Output is correct
49 Correct 35 ms 560 KB Output is correct
50 Correct 23 ms 428 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 19 ms 468 KB Output is correct
53 Correct 23 ms 452 KB Output is correct
54 Correct 39 ms 596 KB Output is correct
55 Correct 32 ms 604 KB Output is correct
56 Correct 32 ms 632 KB Output is correct
57 Correct 5 ms 340 KB Output is correct
58 Correct 14 ms 360 KB Output is correct
59 Correct 4 ms 332 KB Output is correct
60 Correct 35 ms 552 KB Output is correct
61 Correct 36 ms 648 KB Output is correct
62 Correct 5 ms 340 KB Output is correct
63 Correct 37 ms 588 KB Output is correct
64 Correct 22 ms 508 KB Output is correct
65 Execution timed out 2041 ms 12972 KB Time limit exceeded
66 Halted 0 ms 0 KB -