Submission #95841

# Submission time Handle Problem Language Result Execution time Memory
95841 2019-02-03T03:18:06 Z diamond_duke Cultivation (JOI17_cultivation) C++11
100 / 100
1257 ms 1144 KB
#include <algorithm>
#include <cstdio>
using ll = long long;
std::pair<ll, int> imp[605];
struct motonic_queue
{
	int que[605], *arr, he, ta;
	motonic_queue(int *_arr) : arr(_arr), he(0), ta(-1) {}
	inline void pop(int pos)
	{
		while (he <= ta && que[he] < pos)
			he++;
	}
	inline void push(int pos)
	{
		while (he <= ta && arr[imp[pos].second] >= arr[imp[que[ta]].second])
			ta--;
		que[++ta] = pos;
	}
	inline ll front() { return arr[imp[que[he]].second]; }
};
struct point { ll x, y; } arr[305];
int idx[305], lp[305], rp[305], H, W, n, cnt;
int sum[200005], A[605], B[605], C[605];
bool vis[605][305];
inline void 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++)
	{
		y = idx[i];
		if (!vis[x][y])
			continue;
		if (-1 == lst)
			A[x] = arr[y].y - 1;
		else
			B[x] = std::max<int>(B[x], arr[y].y - lst - 1);
		lst = arr[y].y;
	}
	C[x] = W - lst;
}
inline ll solve()
{
	motonic_queue que_A(A), que_B(B), que_C(C);
	ll ans = W * 2;
	for (int i = 0, j = 0; i < n * 2 && imp[i].first + H <= imp[n * 2 - 1].first; i++)
	{
		que_A.pop(i);
		que_B.pop(i);
		que_C.pop(i);
		while (j < n * 2 && imp[i].first + H > imp[j].first)
		{
			que_A.push(j);
			que_B.push(j);
			que_C.push(j);
			j++;
		}
		ans = std::min(ans, std::max(que_A.front() + que_C.front(), que_B.front()));
	}
	return ans;
}
int main()
{
	// freopen("loj-2390.in", "r", stdin);
	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; });
	sum[cnt++] = arr[0].x - 1 + H - arr[n - 1].x;
	for (int i = 1; i < n; i++)
		sum[0] = std::max<int>(sum[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 (sum[0] < arr[i].x - arr[j].x - 1 + H)
				sum[cnt++] = arr[i].x - arr[j].x - 1 + H;
			if (i > j && sum[0] < arr[i].x - arr[j].x - 1)
				sum[cnt++] = arr[i].x - arr[j].x - 1;
		}
	}
	std::sort(sum, sum + cnt);
	cnt = std::unique(sum, sum + cnt) - sum;
	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 i = 0; i < cnt; i++)
	{
		for (int j = 0; j < n; j++)
		{
			while (lp[j] < n && arr[j].x + sum[i] >= arr[lp[j]].x)
			{
				if (arr[j].x <= arr[lp[j]].x)
					add(lp[j], j);
				lp[j]++;
			}
			while (rp[j] < n && arr[j].x + sum[i] + 1 >= arr[rp[j]].x)
			{
				if (arr[j].x < arr[rp[j]].x)
					add(j + n, rp[j]);
				rp[j]++;
			}
			imp[j] = {arr[j].x, j};
			imp[j + n] = {arr[j].x + sum[i] + 1, j + n};
		}
		std::merge(imp, imp + n, imp + n, imp + n + n, imp);
		ans = std::min(ans, sum[i] + solve());
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

cultivation.cpp: In function 'int main()':
cultivation.cpp:67: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:69: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 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 252 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 252 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 6 ms 504 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 16 ms 760 KB Output is correct
25 Correct 9 ms 632 KB Output is correct
26 Correct 44 ms 1104 KB Output is correct
27 Correct 45 ms 1100 KB Output is correct
28 Correct 29 ms 632 KB Output is correct
29 Correct 44 ms 1016 KB Output is correct
30 Correct 44 ms 1144 KB Output is correct
31 Correct 44 ms 1016 KB Output is correct
32 Correct 44 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 252 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 6 ms 504 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 16 ms 760 KB Output is correct
25 Correct 9 ms 632 KB Output is correct
26 Correct 44 ms 1104 KB Output is correct
27 Correct 45 ms 1100 KB Output is correct
28 Correct 29 ms 632 KB Output is correct
29 Correct 44 ms 1016 KB Output is correct
30 Correct 44 ms 1144 KB Output is correct
31 Correct 44 ms 1016 KB Output is correct
32 Correct 44 ms 1016 KB Output is correct
33 Correct 42 ms 760 KB Output is correct
34 Correct 46 ms 1144 KB Output is correct
35 Correct 44 ms 1064 KB Output is correct
36 Correct 46 ms 1016 KB Output is correct
37 Correct 48 ms 1016 KB Output is correct
38 Correct 44 ms 1044 KB Output is correct
39 Correct 77 ms 1056 KB Output is correct
40 Correct 50 ms 1016 KB Output is correct
41 Correct 44 ms 888 KB Output is correct
42 Correct 44 ms 888 KB Output is correct
43 Correct 48 ms 1016 KB Output is correct
44 Correct 62 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 30 ms 504 KB Output is correct
22 Correct 48 ms 504 KB Output is correct
23 Correct 33 ms 504 KB Output is correct
24 Correct 32 ms 376 KB Output is correct
25 Correct 51 ms 504 KB Output is correct
26 Correct 21 ms 376 KB Output is correct
27 Correct 46 ms 504 KB Output is correct
28 Correct 48 ms 528 KB Output is correct
29 Correct 41 ms 376 KB Output is correct
30 Correct 50 ms 448 KB Output is correct
31 Correct 47 ms 376 KB Output is correct
32 Correct 45 ms 528 KB Output is correct
33 Correct 31 ms 504 KB Output is correct
34 Correct 45 ms 504 KB Output is correct
35 Correct 45 ms 504 KB Output is correct
36 Correct 31 ms 536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 252 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 6 ms 504 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 16 ms 760 KB Output is correct
25 Correct 9 ms 632 KB Output is correct
26 Correct 44 ms 1104 KB Output is correct
27 Correct 45 ms 1100 KB Output is correct
28 Correct 29 ms 632 KB Output is correct
29 Correct 44 ms 1016 KB Output is correct
30 Correct 44 ms 1144 KB Output is correct
31 Correct 44 ms 1016 KB Output is correct
32 Correct 44 ms 1016 KB Output is correct
33 Correct 42 ms 760 KB Output is correct
34 Correct 46 ms 1144 KB Output is correct
35 Correct 44 ms 1064 KB Output is correct
36 Correct 46 ms 1016 KB Output is correct
37 Correct 48 ms 1016 KB Output is correct
38 Correct 44 ms 1044 KB Output is correct
39 Correct 77 ms 1056 KB Output is correct
40 Correct 50 ms 1016 KB Output is correct
41 Correct 44 ms 888 KB Output is correct
42 Correct 44 ms 888 KB Output is correct
43 Correct 48 ms 1016 KB Output is correct
44 Correct 62 ms 1016 KB Output is correct
45 Correct 2 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 2 ms 376 KB Output is correct
48 Correct 3 ms 376 KB Output is correct
49 Correct 3 ms 376 KB Output is correct
50 Correct 2 ms 376 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 3 ms 376 KB Output is correct
53 Correct 2 ms 376 KB Output is correct
54 Correct 2 ms 376 KB Output is correct
55 Correct 3 ms 376 KB Output is correct
56 Correct 3 ms 376 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 2 ms 376 KB Output is correct
59 Correct 2 ms 376 KB Output is correct
60 Correct 2 ms 376 KB Output is correct
61 Correct 2 ms 376 KB Output is correct
62 Correct 2 ms 376 KB Output is correct
63 Correct 3 ms 376 KB Output is correct
64 Correct 2 ms 376 KB Output is correct
65 Correct 30 ms 504 KB Output is correct
66 Correct 48 ms 504 KB Output is correct
67 Correct 33 ms 504 KB Output is correct
68 Correct 32 ms 376 KB Output is correct
69 Correct 51 ms 504 KB Output is correct
70 Correct 21 ms 376 KB Output is correct
71 Correct 46 ms 504 KB Output is correct
72 Correct 48 ms 528 KB Output is correct
73 Correct 41 ms 376 KB Output is correct
74 Correct 50 ms 448 KB Output is correct
75 Correct 47 ms 376 KB Output is correct
76 Correct 45 ms 528 KB Output is correct
77 Correct 31 ms 504 KB Output is correct
78 Correct 45 ms 504 KB Output is correct
79 Correct 45 ms 504 KB Output is correct
80 Correct 31 ms 536 KB Output is correct
81 Correct 497 ms 860 KB Output is correct
82 Correct 474 ms 760 KB Output is correct
83 Correct 571 ms 888 KB Output is correct
84 Correct 625 ms 888 KB Output is correct
85 Correct 1208 ms 1080 KB Output is correct
86 Correct 1133 ms 1068 KB Output is correct
87 Correct 853 ms 1072 KB Output is correct
88 Correct 820 ms 912 KB Output is correct
89 Correct 899 ms 940 KB Output is correct
90 Correct 562 ms 828 KB Output is correct
91 Correct 1158 ms 1052 KB Output is correct
92 Correct 1223 ms 1076 KB Output is correct
93 Correct 900 ms 944 KB Output is correct
94 Correct 1143 ms 1084 KB Output is correct
95 Correct 1202 ms 1076 KB Output is correct
96 Correct 1152 ms 1028 KB Output is correct
97 Correct 1257 ms 1084 KB Output is correct
98 Correct 46 ms 888 KB Output is correct