Submission #1075508

# Submission time Handle Problem Language Result Execution time Memory
1075508 2024-08-26T07:11:18 Z qwerasdfzxcl Cultivation (JOI17_cultivation) C++17
100 / 100
1701 ms 4816 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

constexpr ll INF = 4e18;

pair<ll, ll> P[303];
ll a[303], S[707], E[707], X[3][707], dp[303][303], FUCK[2][303][303], L, U;
int dq[3][707], n;

pair<ll, int> V[303];
int f[303], g[303];

ll solve(ll len){
	int sz = 0;

	for (int i=1,j=1;i<=n||j<=n;){
		ll s = min(a[i], a[j]+len);
		while(a[i]==s || a[j]+len==s){
			if (a[i]==s) i++;
			if (a[j]+len==s) j++;
		}

		if (j > n) break;
		ll e = min(a[i], a[j]+len);

		assert(j < i);
	
		++sz;
		S[sz] = s, E[sz] = e;
		X[0][sz] = FUCK[0][j][i-1], X[1][sz] = FUCK[1][j][i-1], X[2][sz] = dp[j][i-1];

	}

	ll ret = INF;
	int pl[3] = {1, 1, 1}, pr[3] = {1, 1, 1};

	for (int i=1,j=1;i<=sz;i++){
		for (int z=0;z<3;z++) while(pl[z] < pr[z] && dq[z][pl[z]] < i) pl[z]++;
		while(j <= sz && E[j-1]-S[i] < L){
			for (int z=0;z<3;z++){
				while(pl[z] < pr[z] && X[z][dq[z][pr[z]-1]] <= X[z][j]) pr[z]--;
				dq[z][pr[z]] = j;
				pr[z]++;
			}
			j++;
		}

		if (j > sz && E[j-1]-S[i] < L) break;
		for (int z=0;z<3;z++) assert(pl[z] < pr[z]);

		ret = min(ret, max(X[0][dq[0][pl[0]]] + X[1][dq[1][pl[1]]], X[2][dq[2][pl[2]]]));
	}

	return ret + len - 1;
}

int main(){
	scanf("%lld %lld", &L, &U);
	scanf("%d", &n);
	for (int i=1;i<=n;i++) scanf("%lld %lld", &P[i].first, &P[i].second);
	sort(P+1, P+n+1);

	auto st = clock();

	for (int i=1;i<=n;i++) a[i] = P[i].first;
	for (int i=n;i>0;i--){
		int sz = 0;
		V[sz++] = {0, 0};
		for (int j=n;j>=i;j--){
			V[sz++] = {P[j].second, j};
		}
		V[sz++] = {U+1, n+1};
		sort(V, V+sz);

		for (int i=0;i<sz-1;i++) f[V[i].second] = V[i+1].second, g[V[i+1].second] = V[i].second;

		for (int j=1;j<sz;j++) dp[i][n] = max(dp[i][n], V[j].first - V[j-1].first - 1);
		FUCK[0][i][n] = P[f[0]].second - 1;
		FUCK[1][i][n] = U - P[g[n+1]].second;

		for (int j=n-1;j>=i;j--){
			int ff = f[j+1], gg = g[j+1];
			g[ff] = gg;
			f[gg] = ff;

			dp[i][j] = max(dp[i][j+1], P[ff].second - P[gg].second - 1);
			FUCK[0][i][j] = P[f[0]].second - 1;
			FUCK[1][i][j] = U - P[g[n+1]].second;
		}
	}

	ll mn = 0;
	for (int i=2;i<=n;i++) mn = max(mn, a[i] - a[i-1]);
	mn = max(mn, (L-a[n]) + a[1]);
	a[n+1] = INF;

	ll ans = INF;
	vector<ll> C = {L};
	for (int i=1;i<=n;i++){
		for (int j=i+1;j<=n;j++){
			if (a[j]-a[i] >= mn) C.push_back(a[j]-a[i]);
			if (L-a[j]+a[i] >= mn) C.push_back(L-a[j]+a[i]);
			if (L+a[j]-a[i] >= mn) C.push_back(L+a[j]-a[i]);
		}
	}

	sort(C.begin(), C.end());
	C.erase(unique(C.begin(), C.end()), C.end());

	assert((double)(clock() - st) / CLOCKS_PER_SEC < 1.0);
	for (auto &x:C) ans = min(ans, solve(x));

	cout << ans << '\n';
}

Compilation message

cultivation.cpp: In function 'int main()':
cultivation.cpp:60:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |  scanf("%lld %lld", &L, &U);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~
cultivation.cpp:61:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
cultivation.cpp:62:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |  for (int i=1;i<=n;i++) scanf("%lld %lld", &P[i].first, &P[i].second);
      |                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 1 ms 860 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 2 ms 1628 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 4 ms 2520 KB Output is correct
25 Correct 2 ms 1884 KB Output is correct
26 Correct 8 ms 4592 KB Output is correct
27 Correct 8 ms 4660 KB Output is correct
28 Correct 4 ms 2520 KB Output is correct
29 Correct 7 ms 4560 KB Output is correct
30 Correct 8 ms 4556 KB Output is correct
31 Correct 7 ms 4560 KB Output is correct
32 Correct 7 ms 4560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 1 ms 860 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 2 ms 1628 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 4 ms 2520 KB Output is correct
25 Correct 2 ms 1884 KB Output is correct
26 Correct 8 ms 4592 KB Output is correct
27 Correct 8 ms 4660 KB Output is correct
28 Correct 4 ms 2520 KB Output is correct
29 Correct 7 ms 4560 KB Output is correct
30 Correct 8 ms 4556 KB Output is correct
31 Correct 7 ms 4560 KB Output is correct
32 Correct 7 ms 4560 KB Output is correct
33 Correct 4 ms 3536 KB Output is correct
34 Correct 8 ms 4560 KB Output is correct
35 Correct 8 ms 4572 KB Output is correct
36 Correct 8 ms 4560 KB Output is correct
37 Correct 7 ms 4560 KB Output is correct
38 Correct 7 ms 4756 KB Output is correct
39 Correct 8 ms 4560 KB Output is correct
40 Correct 7 ms 4560 KB Output is correct
41 Correct 7 ms 3540 KB Output is correct
42 Correct 6 ms 3540 KB Output is correct
43 Correct 7 ms 4560 KB Output is correct
44 Correct 7 ms 4812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 648 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 436 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 688 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 856 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 648 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 436 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 688 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 856 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 688 KB Output is correct
21 Correct 36 ms 1368 KB Output is correct
22 Correct 62 ms 1368 KB Output is correct
23 Correct 41 ms 1372 KB Output is correct
24 Correct 40 ms 1372 KB Output is correct
25 Correct 59 ms 1372 KB Output is correct
26 Correct 18 ms 1368 KB Output is correct
27 Correct 60 ms 1368 KB Output is correct
28 Correct 59 ms 1368 KB Output is correct
29 Correct 54 ms 1372 KB Output is correct
30 Correct 63 ms 1368 KB Output is correct
31 Correct 65 ms 1372 KB Output is correct
32 Correct 58 ms 1372 KB Output is correct
33 Correct 40 ms 1368 KB Output is correct
34 Correct 57 ms 1208 KB Output is correct
35 Correct 61 ms 1368 KB Output is correct
36 Correct 43 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 1 ms 860 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 2 ms 1628 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 4 ms 2520 KB Output is correct
25 Correct 2 ms 1884 KB Output is correct
26 Correct 8 ms 4592 KB Output is correct
27 Correct 8 ms 4660 KB Output is correct
28 Correct 4 ms 2520 KB Output is correct
29 Correct 7 ms 4560 KB Output is correct
30 Correct 8 ms 4556 KB Output is correct
31 Correct 7 ms 4560 KB Output is correct
32 Correct 7 ms 4560 KB Output is correct
33 Correct 4 ms 3536 KB Output is correct
34 Correct 8 ms 4560 KB Output is correct
35 Correct 8 ms 4572 KB Output is correct
36 Correct 8 ms 4560 KB Output is correct
37 Correct 7 ms 4560 KB Output is correct
38 Correct 7 ms 4756 KB Output is correct
39 Correct 8 ms 4560 KB Output is correct
40 Correct 7 ms 4560 KB Output is correct
41 Correct 7 ms 3540 KB Output is correct
42 Correct 6 ms 3540 KB Output is correct
43 Correct 7 ms 4560 KB Output is correct
44 Correct 7 ms 4812 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 1 ms 600 KB Output is correct
48 Correct 1 ms 648 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 600 KB Output is correct
52 Correct 1 ms 604 KB Output is correct
53 Correct 1 ms 436 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 1 ms 688 KB Output is correct
56 Correct 2 ms 604 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 1 ms 856 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 604 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 1 ms 604 KB Output is correct
64 Correct 1 ms 688 KB Output is correct
65 Correct 36 ms 1368 KB Output is correct
66 Correct 62 ms 1368 KB Output is correct
67 Correct 41 ms 1372 KB Output is correct
68 Correct 40 ms 1372 KB Output is correct
69 Correct 59 ms 1372 KB Output is correct
70 Correct 18 ms 1368 KB Output is correct
71 Correct 60 ms 1368 KB Output is correct
72 Correct 59 ms 1368 KB Output is correct
73 Correct 54 ms 1372 KB Output is correct
74 Correct 63 ms 1368 KB Output is correct
75 Correct 65 ms 1372 KB Output is correct
76 Correct 58 ms 1372 KB Output is correct
77 Correct 40 ms 1368 KB Output is correct
78 Correct 57 ms 1208 KB Output is correct
79 Correct 61 ms 1368 KB Output is correct
80 Correct 43 ms 1372 KB Output is correct
81 Correct 666 ms 3028 KB Output is correct
82 Correct 658 ms 3028 KB Output is correct
83 Correct 749 ms 3284 KB Output is correct
84 Correct 982 ms 3284 KB Output is correct
85 Correct 1656 ms 4556 KB Output is correct
86 Correct 1612 ms 4556 KB Output is correct
87 Correct 1052 ms 4560 KB Output is correct
88 Correct 1169 ms 3540 KB Output is correct
89 Correct 1260 ms 3540 KB Output is correct
90 Correct 871 ms 3540 KB Output is correct
91 Correct 1555 ms 3728 KB Output is correct
92 Correct 1701 ms 4560 KB Output is correct
93 Correct 1286 ms 3540 KB Output is correct
94 Correct 1696 ms 4560 KB Output is correct
95 Correct 1663 ms 4816 KB Output is correct
96 Correct 1585 ms 3536 KB Output is correct
97 Correct 1644 ms 4556 KB Output is correct
98 Correct 4 ms 3536 KB Output is correct