Submission #547409

# Submission time Handle Problem Language Result Execution time Memory
547409 2022-04-10T16:10:11 Z skittles1412 Sightseeing in Kyoto (JOI22_kyoto) C++17
100 / 100
30 ms 6504 KB
#include "bits/extc++.h"

using namespace std;

template <typename T>
void dbgh(const T& t) {
	cerr << t << endl;
}

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
	cerr << t << " | ";
	dbgh(u...);
}

#ifdef DEBUG
#define dbg(...)                                           \
	cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
		 << ": ";                                          \
	dbgh(__VA_ARGS__)
#else
#define cerr   \
	if (false) \
	cerr
#define dbg(...)
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())

using C = complex<long>;

long ccw(const C& a, C b, C c) {
	b -= a;
	c -= a;
	return (c * conj(b)).imag();
}

long ccw(const pair<long, long>& a, const pair<long, long>& b, const pair<long, long>& c) {
	return ccw(C {a.first, a.second}, C {b.first, b.second}, C {c.first, c.second});
}

vector<pair<long, long>> convex(const vector<long>& arr) {
	vector<pair<long, long>> ans;
	for (int i = 0; i < sz(arr); i++) {
		while (sz(ans) >= 2 && ccw(ans[sz(ans) - 2], ans[sz(ans) - 1], {i, arr[i]}) < 0) {
			ans.pop_back();
		}
		ans.emplace_back(i, arr[i]);
	}
	return ans;
}

void solve() {
	dbg(ccw(C {0, 1}, C {1, 2}, C {2, 1}));
	dbg(sz(convex({1, 2, 1})));
	int n, m;
	cin >> n >> m;
	vector<long> ina(n), inb(m);
	for (auto& a : ina) {
		cin >> a;
	}
	for (auto& a : inb) {
		cin >> a;
	}
	vector<pair<long, long>> arra = convex(ina), arrb = convex(inb);
	n = sz(arra);
	m = sz(arrb);
	dbg(n, m);
	int i = 0, j = 0;
	long ans = 0;
	while (i + 1 < n || j + 1 < m) {
		bool a;
		if (i + 1 == n) {
			a = false;
		} else if (j + 1 == m) {
			a = true;
		} else {
			a = (arra[i + 1].second - arra[i].second) * (arrb[j + 1].first - arrb[j].first) <=
				(arrb[j + 1].second - arrb[j].second) * (arra[i + 1].first - arra[i].first);
		}
		dbg(a);
		if (a) {
			ans += (arra[i + 1].first - arra[i].first) * arrb[j].second;
			i++;
		} else {
			ans += (arrb[j + 1].first - arrb[j].first) * arra[i].second;
			j++;
		}
	}
	cout << ans << endl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cin.exceptions(ios::failbit);
	solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 264 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 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 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 9 ms 852 KB Output is correct
5 Correct 7 ms 936 KB Output is correct
6 Correct 3 ms 468 KB Output is correct
7 Correct 17 ms 1908 KB Output is correct
8 Correct 16 ms 1876 KB Output is correct
9 Correct 18 ms 1876 KB Output is correct
10 Correct 21 ms 1904 KB Output is correct
11 Correct 21 ms 2164 KB Output is correct
12 Correct 19 ms 1876 KB Output is correct
13 Correct 16 ms 1876 KB Output is correct
14 Correct 20 ms 1896 KB Output is correct
15 Correct 23 ms 6504 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 264 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 9 ms 852 KB Output is correct
33 Correct 7 ms 936 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 17 ms 1908 KB Output is correct
36 Correct 16 ms 1876 KB Output is correct
37 Correct 18 ms 1876 KB Output is correct
38 Correct 21 ms 1904 KB Output is correct
39 Correct 21 ms 2164 KB Output is correct
40 Correct 19 ms 1876 KB Output is correct
41 Correct 16 ms 1876 KB Output is correct
42 Correct 20 ms 1896 KB Output is correct
43 Correct 23 ms 6504 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 12 ms 980 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 2 ms 340 KB Output is correct
58 Correct 4 ms 468 KB Output is correct
59 Correct 24 ms 1876 KB Output is correct
60 Correct 22 ms 1876 KB Output is correct
61 Correct 26 ms 1876 KB Output is correct
62 Correct 27 ms 1876 KB Output is correct
63 Correct 30 ms 6220 KB Output is correct
64 Correct 25 ms 1880 KB Output is correct
65 Correct 26 ms 1876 KB Output is correct
66 Correct 25 ms 1876 KB Output is correct
67 Correct 28 ms 6476 KB Output is correct