Submission #561568

# Submission time Handle Problem Language Result Execution time Memory
561568 2022-05-13T07:29:08 Z 8e7 Sightseeing in Kyoto (JOI22_kyoto) C++17
100 / 100
36 ms 5576 KB
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 100005
#define pii pair<ll, ll>
#define x first
#define y second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
const ll inf = 1LL<<60;
pii vec(pii p, pii q){return {q.x - p.x, q.y - p.y};}
ll cross(pii p, pii q){return p.x * q.y - p.y * q.x;}

ll a[maxn], b[maxn];
int main() {
	io
	int n, m;
	cin >> n >> m;
	for (int i = 0;i < n;i++) cin >> a[i];	
	for (int i = 0;i < m;i++) cin >> b[i];
	vector<pii> hl, hr;
	auto build_hull = [&] (int N, ll arr[], vector<pii> &v) {
		for (int i = 0;i < N;i++) {
			pii p = {i, arr[i]};
			while (v.size() > 1) {
				pii p1 = v[v.size() - 2], p2 = v.back();
				if (cross(vec(p2, p), vec(p2, p1)) <= 0) {
					v.pop_back();
				} else {
					break;
				}
			}
			v.push_back(p);
		}
	};
	build_hull(n, a, hl);
	build_hull(m, b, hr);
	ll ans = 0;	
	while (hl.size() > 1 || hr.size() > 1) {
		if (hl.size() == 1) {
			ans += hr.back().x * a[0];
			break;
		} else if (hr.size() == 1) {
			ans += hl.back().x * b[0];
			break;
		} else {
			ll ai = hl[hl.size()-2].y, aj = hl.back().y, bi = hr[hr.size()-2].y, bj = hr.back().y;
			ll X = hl.back().x - hl[hl.size()-2].x, Y = hr.back().x - hr[hr.size()-2].x;
			if ((bj - bi) * X < (aj - ai) * Y) {
				ans += bj * X;
				hl.pop_back();
			} else {
				ans += aj * Y;	
				hr.pop_back();
			}
		}
	}
	cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 7 ms 1236 KB Output is correct
5 Correct 7 ms 1108 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 15 ms 2516 KB Output is correct
8 Correct 18 ms 2576 KB Output is correct
9 Correct 18 ms 2560 KB Output is correct
10 Correct 16 ms 2436 KB Output is correct
11 Correct 14 ms 2508 KB Output is correct
12 Correct 15 ms 2552 KB Output is correct
13 Correct 19 ms 2572 KB Output is correct
14 Correct 14 ms 2520 KB Output is correct
15 Correct 16 ms 2796 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 328 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 328 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 7 ms 1236 KB Output is correct
33 Correct 7 ms 1108 KB Output is correct
34 Correct 3 ms 596 KB Output is correct
35 Correct 15 ms 2516 KB Output is correct
36 Correct 18 ms 2576 KB Output is correct
37 Correct 18 ms 2560 KB Output is correct
38 Correct 16 ms 2436 KB Output is correct
39 Correct 14 ms 2508 KB Output is correct
40 Correct 15 ms 2552 KB Output is correct
41 Correct 19 ms 2572 KB Output is correct
42 Correct 14 ms 2520 KB Output is correct
43 Correct 16 ms 2796 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 328 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 11 ms 1752 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 468 KB Output is correct
58 Correct 3 ms 800 KB Output is correct
59 Correct 25 ms 3656 KB Output is correct
60 Correct 26 ms 3508 KB Output is correct
61 Correct 29 ms 3324 KB Output is correct
62 Correct 24 ms 3476 KB Output is correct
63 Correct 25 ms 5576 KB Output is correct
64 Correct 24 ms 3576 KB Output is correct
65 Correct 24 ms 3696 KB Output is correct
66 Correct 22 ms 3688 KB Output is correct
67 Correct 36 ms 3012 KB Output is correct