답안 #802088

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
802088 2023-08-02T09:41:00 Z flappybird Cultivation (JOI17_cultivation) C++17
80 / 100
1909 ms 12748 KB
#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 202020
#define MAXS 20
#define INF 2000000000000020
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define MOD 1000000007
ll H, W;
int N;
pii arr[MAX];
ll ans = 2e9;
vector<int> st[MAX], en[MAX];
int U[MAX], D[MAX], UD[MAX];
deque<pii> up, down, su;
bool test(ll d) {
	if (d <= 0) return false;
	vector<ll> ys;
	int i, j;
	for (i = 1; i <= N; i++) ys.push_back(arr[i].second), ys.push_back(arr[i].second + d);
	sort(ys.begin(), ys.end());
	ys.erase(unique(ys.begin(), ys.end()), ys.end());
	int X = ys.size();
	multiset<int> ds, alls;
	for (i = 0; i < X; i++) U[i] = D[i] = UD[i] = 0, st[i].clear(), en[i].clear();
	for (i = 1; i <= N; i++) {
		int l, r;
		l = lower_bound(ys.begin(), ys.end(), arr[i].second) - ys.begin();
		r = lower_bound(ys.begin(), ys.end(), arr[i].second + d) - ys.begin();
		st[l].push_back(i);
		en[r].push_back(i);
	}
	for (i = 0; i < X; i++) {
		for (auto v : st[i]) {
			int x = arr[v].first;
			if (alls.size() && alls.find(x) == alls.end()) {
				auto it = alls.lower_bound(x);
				if (it == alls.end()) ds.insert(x - *(--it) - 1);
				else if (it == alls.begin()) ds.insert(*it - x - 1);
				else {
					int ne = *it;
					it--;
					int pv = *it;
					ds.erase(ds.find(ne - pv - 1));
					ds.insert(ne - x - 1);
					ds.insert(x - pv - 1);
				}
			}
			alls.insert(x);
		}
		for (auto v : en[i]) {
			int x = arr[v].first;
			alls.erase(alls.find(x));
			if (alls.size() && alls.find(x) == alls.end()) {
				auto it = alls.lower_bound(x);
				if (it == alls.end()) ds.erase(ds.find(x - *(--it) - 1));
				else if (it == alls.begin()) ds.erase(ds.find(*it - x - 1));
				else {
					ll ne = *it;
					it--;
					ll pv = *it;
					ds.insert(ne - pv - 1);
					ds.erase(ds.find(ne - x - 1));
					ds.erase(ds.find(x - pv - 1));
				}
			}
		}
		if (ds.size()) UD[i] = *ds.rbegin();
		if (alls.empty()) UD[i] = 2e9;
		else {
			U[i] = *alls.begin() - 1;
			D[i] = H - *alls.rbegin();
		}
	}
	up.clear();
	down.clear();
	su.clear();
	ll mn = INF;
	j = 0;
	for (i = 0; i < X - 1; i++) {
		while (up.size() && up.back().first <= U[i]) up.pop_back();
		up.emplace_back(U[i], i);
		while (down.size() && down.back().first <= D[i]) down.pop_back();
		down.emplace_back(D[i], i);
		while (su.size() && su.back().first <= UD[i]) su.pop_back();
		su.emplace_back(UD[i], i);
		while (j + 1 <= i && ys[i + 1] - ys[j + 1] >= W) j++;
		while (up.size() && up.front().second < j) up.pop_front();
		while (down.size() && down.front().second < j) down.pop_front();
		while (su.size() && su.front().second < j) su.pop_front();
		if (ys[i + 1] - ys[j] >= W) mn = min(mn, max(0ll + up.front().first + down.front().first, (ll)su.front().first));
	}
	if (mn >= INF) return false;
	ans = min(ans, mn + d - 1);
	return true;
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	clock_t start, finish;
	cin >> H >> W >> N;
	start = clock();
	swap(H, W);
	int i, j;
	vector<ll> ls;
	ls.push_back(W);
	for (i = 1; i <= N; i++) cin >> arr[i].first >> arr[i].second, swap(arr[i].first, arr[i].second);
	for (i = 1; i <= N; i++) {
		for (j = i + 1; j <= N; j++) ls.push_back(abs(arr[j].second - arr[i].second));
		for (j = i + 1; j <= N; j++) ls.push_back(abs(arr[j].second - arr[i].second) + W);
		ls.push_back(arr[i].second);
		ls.push_back(W - arr[i].second + 1);
	}
	vector<ll> cpy;
	for (auto v : ls) cpy.push_back(W - v);
	for (auto v : cpy) ls.push_back(v);
	sort(ls.begin(), ls.end());
	ls.erase(unique(ls.begin(), ls.end()), ls.end());
	reverse(ls.begin(), ls.end());
	while (ls.back() <= 0) ls.pop_back();
	for (i = (int)ls.size() - 1; i >= 0; i--) swap(ls[i], ls[rand() % (i + 1)]);
	ll mv = 0;
	int rot = 100;
	for (auto v : ls) {
		if (v < mv) continue;
		if (!test(v)) mv = max(mv, v);
		rot--;
		if (!rot) {
			rot = 100;
			finish = clock();
			auto duration = (double)(finish - start) / (double)CLOCKS_PER_SEC;
			if (duration > 1.9) break;
		}
	}
	cout << ans << ln;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9812 KB Output is correct
2 Correct 6 ms 9824 KB Output is correct
3 Correct 5 ms 9792 KB Output is correct
4 Correct 6 ms 9732 KB Output is correct
5 Correct 5 ms 9812 KB Output is correct
6 Correct 5 ms 9812 KB Output is correct
7 Correct 5 ms 9812 KB Output is correct
8 Correct 5 ms 9812 KB Output is correct
9 Correct 5 ms 9812 KB Output is correct
10 Correct 6 ms 9812 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 5 ms 9812 KB Output is correct
13 Correct 5 ms 9812 KB Output is correct
14 Correct 5 ms 9812 KB Output is correct
15 Correct 5 ms 9812 KB Output is correct
16 Correct 5 ms 9824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9812 KB Output is correct
2 Correct 6 ms 9824 KB Output is correct
3 Correct 5 ms 9792 KB Output is correct
4 Correct 6 ms 9732 KB Output is correct
5 Correct 5 ms 9812 KB Output is correct
6 Correct 5 ms 9812 KB Output is correct
7 Correct 5 ms 9812 KB Output is correct
8 Correct 5 ms 9812 KB Output is correct
9 Correct 5 ms 9812 KB Output is correct
10 Correct 6 ms 9812 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 5 ms 9812 KB Output is correct
13 Correct 5 ms 9812 KB Output is correct
14 Correct 5 ms 9812 KB Output is correct
15 Correct 5 ms 9812 KB Output is correct
16 Correct 5 ms 9824 KB Output is correct
17 Correct 5 ms 9812 KB Output is correct
18 Correct 6 ms 10076 KB Output is correct
19 Correct 6 ms 9820 KB Output is correct
20 Correct 5 ms 9812 KB Output is correct
21 Correct 7 ms 9956 KB Output is correct
22 Correct 10 ms 10332 KB Output is correct
23 Correct 5 ms 9820 KB Output is correct
24 Correct 14 ms 11216 KB Output is correct
25 Correct 12 ms 10560 KB Output is correct
26 Correct 25 ms 12748 KB Output is correct
27 Correct 21 ms 12748 KB Output is correct
28 Correct 14 ms 11224 KB Output is correct
29 Correct 21 ms 12748 KB Output is correct
30 Correct 21 ms 12620 KB Output is correct
31 Correct 22 ms 12620 KB Output is correct
32 Correct 22 ms 12748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9812 KB Output is correct
2 Correct 6 ms 9824 KB Output is correct
3 Correct 5 ms 9792 KB Output is correct
4 Correct 6 ms 9732 KB Output is correct
5 Correct 5 ms 9812 KB Output is correct
6 Correct 5 ms 9812 KB Output is correct
7 Correct 5 ms 9812 KB Output is correct
8 Correct 5 ms 9812 KB Output is correct
9 Correct 5 ms 9812 KB Output is correct
10 Correct 6 ms 9812 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 5 ms 9812 KB Output is correct
13 Correct 5 ms 9812 KB Output is correct
14 Correct 5 ms 9812 KB Output is correct
15 Correct 5 ms 9812 KB Output is correct
16 Correct 5 ms 9824 KB Output is correct
17 Correct 5 ms 9812 KB Output is correct
18 Correct 6 ms 10076 KB Output is correct
19 Correct 6 ms 9820 KB Output is correct
20 Correct 5 ms 9812 KB Output is correct
21 Correct 7 ms 9956 KB Output is correct
22 Correct 10 ms 10332 KB Output is correct
23 Correct 5 ms 9820 KB Output is correct
24 Correct 14 ms 11216 KB Output is correct
25 Correct 12 ms 10560 KB Output is correct
26 Correct 25 ms 12748 KB Output is correct
27 Correct 21 ms 12748 KB Output is correct
28 Correct 14 ms 11224 KB Output is correct
29 Correct 21 ms 12748 KB Output is correct
30 Correct 21 ms 12620 KB Output is correct
31 Correct 22 ms 12620 KB Output is correct
32 Correct 22 ms 12748 KB Output is correct
33 Correct 10 ms 12748 KB Output is correct
34 Correct 27 ms 12620 KB Output is correct
35 Correct 29 ms 12632 KB Output is correct
36 Correct 33 ms 12628 KB Output is correct
37 Correct 32 ms 12696 KB Output is correct
38 Correct 37 ms 12632 KB Output is correct
39 Correct 33 ms 12684 KB Output is correct
40 Correct 32 ms 12620 KB Output is correct
41 Correct 29 ms 12636 KB Output is correct
42 Correct 30 ms 12748 KB Output is correct
43 Correct 33 ms 12620 KB Output is correct
44 Correct 28 ms 12628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 9812 KB Output is correct
2 Correct 13 ms 9812 KB Output is correct
3 Correct 15 ms 9876 KB Output is correct
4 Correct 12 ms 9820 KB Output is correct
5 Correct 15 ms 9824 KB Output is correct
6 Correct 10 ms 9940 KB Output is correct
7 Correct 5 ms 9812 KB Output is correct
8 Correct 14 ms 9824 KB Output is correct
9 Correct 9 ms 9812 KB Output is correct
10 Correct 14 ms 9812 KB Output is correct
11 Correct 17 ms 9876 KB Output is correct
12 Correct 15 ms 9876 KB Output is correct
13 Correct 7 ms 9940 KB Output is correct
14 Correct 10 ms 9884 KB Output is correct
15 Correct 6 ms 9816 KB Output is correct
16 Correct 16 ms 9828 KB Output is correct
17 Correct 14 ms 9824 KB Output is correct
18 Correct 8 ms 9812 KB Output is correct
19 Correct 16 ms 9812 KB Output is correct
20 Correct 12 ms 9824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 9812 KB Output is correct
2 Correct 13 ms 9812 KB Output is correct
3 Correct 15 ms 9876 KB Output is correct
4 Correct 12 ms 9820 KB Output is correct
5 Correct 15 ms 9824 KB Output is correct
6 Correct 10 ms 9940 KB Output is correct
7 Correct 5 ms 9812 KB Output is correct
8 Correct 14 ms 9824 KB Output is correct
9 Correct 9 ms 9812 KB Output is correct
10 Correct 14 ms 9812 KB Output is correct
11 Correct 17 ms 9876 KB Output is correct
12 Correct 15 ms 9876 KB Output is correct
13 Correct 7 ms 9940 KB Output is correct
14 Correct 10 ms 9884 KB Output is correct
15 Correct 6 ms 9816 KB Output is correct
16 Correct 16 ms 9828 KB Output is correct
17 Correct 14 ms 9824 KB Output is correct
18 Correct 8 ms 9812 KB Output is correct
19 Correct 16 ms 9812 KB Output is correct
20 Correct 12 ms 9824 KB Output is correct
21 Correct 592 ms 10324 KB Output is correct
22 Correct 1052 ms 10316 KB Output is correct
23 Correct 497 ms 10208 KB Output is correct
24 Correct 593 ms 10200 KB Output is correct
25 Correct 1071 ms 10200 KB Output is correct
26 Correct 337 ms 10200 KB Output is correct
27 Correct 733 ms 10208 KB Output is correct
28 Correct 1097 ms 10208 KB Output is correct
29 Correct 835 ms 10204 KB Output is correct
30 Correct 1050 ms 10204 KB Output is correct
31 Correct 1089 ms 10200 KB Output is correct
32 Correct 977 ms 10208 KB Output is correct
33 Correct 304 ms 10204 KB Output is correct
34 Correct 909 ms 10208 KB Output is correct
35 Correct 902 ms 10204 KB Output is correct
36 Correct 493 ms 10236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9812 KB Output is correct
2 Correct 6 ms 9824 KB Output is correct
3 Correct 5 ms 9792 KB Output is correct
4 Correct 6 ms 9732 KB Output is correct
5 Correct 5 ms 9812 KB Output is correct
6 Correct 5 ms 9812 KB Output is correct
7 Correct 5 ms 9812 KB Output is correct
8 Correct 5 ms 9812 KB Output is correct
9 Correct 5 ms 9812 KB Output is correct
10 Correct 6 ms 9812 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 5 ms 9812 KB Output is correct
13 Correct 5 ms 9812 KB Output is correct
14 Correct 5 ms 9812 KB Output is correct
15 Correct 5 ms 9812 KB Output is correct
16 Correct 5 ms 9824 KB Output is correct
17 Correct 5 ms 9812 KB Output is correct
18 Correct 6 ms 10076 KB Output is correct
19 Correct 6 ms 9820 KB Output is correct
20 Correct 5 ms 9812 KB Output is correct
21 Correct 7 ms 9956 KB Output is correct
22 Correct 10 ms 10332 KB Output is correct
23 Correct 5 ms 9820 KB Output is correct
24 Correct 14 ms 11216 KB Output is correct
25 Correct 12 ms 10560 KB Output is correct
26 Correct 25 ms 12748 KB Output is correct
27 Correct 21 ms 12748 KB Output is correct
28 Correct 14 ms 11224 KB Output is correct
29 Correct 21 ms 12748 KB Output is correct
30 Correct 21 ms 12620 KB Output is correct
31 Correct 22 ms 12620 KB Output is correct
32 Correct 22 ms 12748 KB Output is correct
33 Correct 10 ms 12748 KB Output is correct
34 Correct 27 ms 12620 KB Output is correct
35 Correct 29 ms 12632 KB Output is correct
36 Correct 33 ms 12628 KB Output is correct
37 Correct 32 ms 12696 KB Output is correct
38 Correct 37 ms 12632 KB Output is correct
39 Correct 33 ms 12684 KB Output is correct
40 Correct 32 ms 12620 KB Output is correct
41 Correct 29 ms 12636 KB Output is correct
42 Correct 30 ms 12748 KB Output is correct
43 Correct 33 ms 12620 KB Output is correct
44 Correct 28 ms 12628 KB Output is correct
45 Correct 8 ms 9812 KB Output is correct
46 Correct 13 ms 9812 KB Output is correct
47 Correct 15 ms 9876 KB Output is correct
48 Correct 12 ms 9820 KB Output is correct
49 Correct 15 ms 9824 KB Output is correct
50 Correct 10 ms 9940 KB Output is correct
51 Correct 5 ms 9812 KB Output is correct
52 Correct 14 ms 9824 KB Output is correct
53 Correct 9 ms 9812 KB Output is correct
54 Correct 14 ms 9812 KB Output is correct
55 Correct 17 ms 9876 KB Output is correct
56 Correct 15 ms 9876 KB Output is correct
57 Correct 7 ms 9940 KB Output is correct
58 Correct 10 ms 9884 KB Output is correct
59 Correct 6 ms 9816 KB Output is correct
60 Correct 16 ms 9828 KB Output is correct
61 Correct 14 ms 9824 KB Output is correct
62 Correct 8 ms 9812 KB Output is correct
63 Correct 16 ms 9812 KB Output is correct
64 Correct 12 ms 9824 KB Output is correct
65 Correct 592 ms 10324 KB Output is correct
66 Correct 1052 ms 10316 KB Output is correct
67 Correct 497 ms 10208 KB Output is correct
68 Correct 593 ms 10200 KB Output is correct
69 Correct 1071 ms 10200 KB Output is correct
70 Correct 337 ms 10200 KB Output is correct
71 Correct 733 ms 10208 KB Output is correct
72 Correct 1097 ms 10208 KB Output is correct
73 Correct 835 ms 10204 KB Output is correct
74 Correct 1050 ms 10204 KB Output is correct
75 Correct 1089 ms 10200 KB Output is correct
76 Correct 977 ms 10208 KB Output is correct
77 Correct 304 ms 10204 KB Output is correct
78 Correct 909 ms 10208 KB Output is correct
79 Correct 902 ms 10204 KB Output is correct
80 Correct 493 ms 10236 KB Output is correct
81 Incorrect 1909 ms 11344 KB Output isn't correct
82 Halted 0 ms 0 KB -