Submission #96982

# Submission time Handle Problem Language Result Execution time Memory
96982 2019-02-13T06:34:39 Z diamond_duke Cultivation (JOI17_cultivation) C++11
100 / 100
1884 ms 1756 KB
#include <algorithm>
#include <cstdio>
using ll = long long;
struct point { ll x, y; } arr[305];
struct queue
{
	int que[605], val[605], he = 0, ta = -1;
	ll *arr;
	queue(ll *_arr) : arr(_arr) {}
	inline void push(int x, int y)
	{
		while (he <= ta && arr[y] >= arr[val[ta]])
			ta--;
		que[++ta] = x;
		val[ta] = y;
	}
	inline void pop(int pos)
	{
		while (he <= ta && que[he] < pos)
			he++;
	}
	inline ll front() const { return arr[val[he]]; }
};
std::pair<ll, int> val[605];
int lp[305], rp[305], idx[305];
ll ava[200005], A[605], B[605], C[605];
bool vis[605][305];
int main()
{
	// freopen("JOISC2017-D1T1.in", "r", stdin);
	int H, W, n, cnt = 0;
	scanf("%d%d%d", &H, &W, &n);
	for (int i = 0; i < n; i++)
		scanf("%lld%lld", &arr[i].x, &arr[i].y);
	std::sort(arr, arr + n, [&] (point a, point b) { return a.x < b.x; });
	ava[cnt++] = arr[0].x - 1 + H - arr[n - 1].x;
	for (int i = 1; i < n; i++)
		ava[0] = std::max(ava[0], arr[i].x - arr[i - 1].x - 1);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (i == j)
				continue;
			if (i > j && arr[i].x - arr[j].x - 1 > ava[0])
				ava[cnt++] = arr[i].x - arr[j].x - 1;
			if (arr[i].x - 1 + H - arr[j].x > ava[0])
				ava[cnt++] = arr[i].x - 1 + H - arr[j].x;
		}
	}
	std::sort(ava, ava + cnt);
	cnt = std::unique(ava, ava + cnt) - ava;
	for (int i = 0; i < n; i++)
		idx[i] = i;
	std::sort(idx, idx + n, [&] (int x, int y) { return arr[x].y < arr[y].y; });
	ll ans = 1e18;
	for (int t = 0; t < cnt; t++)
	{
		auto add = [&] (int x, int y)
		{
			vis[x][y] = true;
			int lst = -1;
			A[x] = B[x] = C[x] = 0;
			for (int i = 0; i < n; i++)
			{
				if (!vis[x][idx[i]])
					continue;
				if (-1 == lst)
					A[x] = arr[idx[i]].y - 1;
				else
					B[x] = std::max(B[x], arr[idx[i]].y - lst - 1);
				lst = arr[idx[i]].y;
			}
			C[x] = W - lst;
		};
		for (int i = 0; i < n; i++)
		{
			while (lp[i] < n && arr[i].x + ava[t] >= arr[lp[i]].x)
			{
				if (arr[i].x <= arr[lp[i]].x)
					add(lp[i], i);
				lp[i]++;
			}
			while (rp[i] < n && arr[i].x + ava[t] + 1 >= arr[rp[i]].x)
			{
				if (arr[i].x < arr[rp[i]].x)
					add(i + n, rp[i]);
				rp[i]++;
			}
			val[i] = {arr[i].x, i};
			val[i + n] = {arr[i].x + ava[t] + 1, i + n};
		}
		std::merge(val, val + n, val + n, val + n * 2, val);
		queue que[] = {A, B, C};
		for (int i = 0, j = 0; i < n * 2 && val[i].first + H <= val[n * 2 - 1].first; i++)
		{
			for (auto &Q : que)
				Q.pop(i);
			while (j < n * 2 && val[i].first + H > val[j].first)
			{
				for (auto &Q : que)
					Q.push(j, val[j].second);
				j++;
			}
			ans = std::min(ans, std::max(que[0].front() + que[2].front(), que[1].front()) + ava[t]);
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

cultivation.cpp: In function 'int main()':
cultivation.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &H, &W, &n);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
cultivation.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &arr[i].x, &arr[i].y);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 2 ms 396 KB Output is correct
18 Correct 4 ms 512 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 7 ms 640 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 16 ms 896 KB Output is correct
25 Correct 11 ms 640 KB Output is correct
26 Correct 41 ms 1536 KB Output is correct
27 Correct 43 ms 1508 KB Output is correct
28 Correct 18 ms 896 KB Output is correct
29 Correct 56 ms 1536 KB Output is correct
30 Correct 49 ms 1536 KB Output is correct
31 Correct 45 ms 1632 KB Output is correct
32 Correct 47 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 2 ms 396 KB Output is correct
18 Correct 4 ms 512 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 7 ms 640 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 16 ms 896 KB Output is correct
25 Correct 11 ms 640 KB Output is correct
26 Correct 41 ms 1536 KB Output is correct
27 Correct 43 ms 1508 KB Output is correct
28 Correct 18 ms 896 KB Output is correct
29 Correct 56 ms 1536 KB Output is correct
30 Correct 49 ms 1536 KB Output is correct
31 Correct 45 ms 1632 KB Output is correct
32 Correct 47 ms 1536 KB Output is correct
33 Correct 40 ms 1024 KB Output is correct
34 Correct 49 ms 1536 KB Output is correct
35 Correct 44 ms 1536 KB Output is correct
36 Correct 42 ms 1664 KB Output is correct
37 Correct 44 ms 1536 KB Output is correct
38 Correct 46 ms 1600 KB Output is correct
39 Correct 47 ms 1536 KB Output is correct
40 Correct 47 ms 1536 KB Output is correct
41 Correct 44 ms 1280 KB Output is correct
42 Correct 51 ms 1408 KB Output is correct
43 Correct 51 ms 1536 KB Output is correct
44 Correct 49 ms 1552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 36 ms 512 KB Output is correct
22 Correct 69 ms 564 KB Output is correct
23 Correct 43 ms 512 KB Output is correct
24 Correct 42 ms 512 KB Output is correct
25 Correct 66 ms 564 KB Output is correct
26 Correct 31 ms 560 KB Output is correct
27 Correct 81 ms 512 KB Output is correct
28 Correct 60 ms 512 KB Output is correct
29 Correct 56 ms 612 KB Output is correct
30 Correct 68 ms 512 KB Output is correct
31 Correct 71 ms 632 KB Output is correct
32 Correct 64 ms 512 KB Output is correct
33 Correct 43 ms 512 KB Output is correct
34 Correct 61 ms 564 KB Output is correct
35 Correct 68 ms 512 KB Output is correct
36 Correct 38 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 4 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 2 ms 396 KB Output is correct
18 Correct 4 ms 512 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 7 ms 640 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 16 ms 896 KB Output is correct
25 Correct 11 ms 640 KB Output is correct
26 Correct 41 ms 1536 KB Output is correct
27 Correct 43 ms 1508 KB Output is correct
28 Correct 18 ms 896 KB Output is correct
29 Correct 56 ms 1536 KB Output is correct
30 Correct 49 ms 1536 KB Output is correct
31 Correct 45 ms 1632 KB Output is correct
32 Correct 47 ms 1536 KB Output is correct
33 Correct 40 ms 1024 KB Output is correct
34 Correct 49 ms 1536 KB Output is correct
35 Correct 44 ms 1536 KB Output is correct
36 Correct 42 ms 1664 KB Output is correct
37 Correct 44 ms 1536 KB Output is correct
38 Correct 46 ms 1600 KB Output is correct
39 Correct 47 ms 1536 KB Output is correct
40 Correct 47 ms 1536 KB Output is correct
41 Correct 44 ms 1280 KB Output is correct
42 Correct 51 ms 1408 KB Output is correct
43 Correct 51 ms 1536 KB Output is correct
44 Correct 49 ms 1552 KB Output is correct
45 Correct 3 ms 384 KB Output is correct
46 Correct 3 ms 384 KB Output is correct
47 Correct 4 ms 384 KB Output is correct
48 Correct 4 ms 384 KB Output is correct
49 Correct 3 ms 384 KB Output is correct
50 Correct 3 ms 384 KB Output is correct
51 Correct 2 ms 384 KB Output is correct
52 Correct 4 ms 384 KB Output is correct
53 Correct 3 ms 384 KB Output is correct
54 Correct 3 ms 384 KB Output is correct
55 Correct 3 ms 384 KB Output is correct
56 Correct 3 ms 384 KB Output is correct
57 Correct 3 ms 384 KB Output is correct
58 Correct 2 ms 384 KB Output is correct
59 Correct 2 ms 384 KB Output is correct
60 Correct 5 ms 384 KB Output is correct
61 Correct 3 ms 384 KB Output is correct
62 Correct 2 ms 384 KB Output is correct
63 Correct 4 ms 384 KB Output is correct
64 Correct 3 ms 384 KB Output is correct
65 Correct 36 ms 512 KB Output is correct
66 Correct 69 ms 564 KB Output is correct
67 Correct 43 ms 512 KB Output is correct
68 Correct 42 ms 512 KB Output is correct
69 Correct 66 ms 564 KB Output is correct
70 Correct 31 ms 560 KB Output is correct
71 Correct 81 ms 512 KB Output is correct
72 Correct 60 ms 512 KB Output is correct
73 Correct 56 ms 612 KB Output is correct
74 Correct 68 ms 512 KB Output is correct
75 Correct 71 ms 632 KB Output is correct
76 Correct 64 ms 512 KB Output is correct
77 Correct 43 ms 512 KB Output is correct
78 Correct 61 ms 564 KB Output is correct
79 Correct 68 ms 512 KB Output is correct
80 Correct 38 ms 512 KB Output is correct
81 Correct 619 ms 1116 KB Output is correct
82 Correct 648 ms 1024 KB Output is correct
83 Correct 716 ms 1264 KB Output is correct
84 Correct 917 ms 1372 KB Output is correct
85 Correct 1720 ms 1644 KB Output is correct
86 Correct 1582 ms 1600 KB Output is correct
87 Correct 1198 ms 1536 KB Output is correct
88 Correct 1168 ms 1372 KB Output is correct
89 Correct 1334 ms 1456 KB Output is correct
90 Correct 774 ms 1024 KB Output is correct
91 Correct 1761 ms 1664 KB Output is correct
92 Correct 1884 ms 1536 KB Output is correct
93 Correct 1157 ms 1396 KB Output is correct
94 Correct 1483 ms 1656 KB Output is correct
95 Correct 1697 ms 1620 KB Output is correct
96 Correct 1516 ms 1656 KB Output is correct
97 Correct 1475 ms 1756 KB Output is correct
98 Correct 51 ms 1276 KB Output is correct