Submission #923631

# Submission time Handle Problem Language Result Execution time Memory
923631 2024-02-07T13:52:45 Z denniskim Sightseeing in Kyoto (JOI22_kyoto) C++17
100 / 100
24 ms 6672 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())

ll n, m;
ll a[100010], b[100010];
ll arr[100010];
vector<pll> cvh;
vector<ll> A, B;
ll ans, x, y;

ll ccw(pll X, pll Y, pll Z)
{
	return (X.fi * Y.se + Y.fi * Z.se + Z.fi * X.se) - (X.se * Y.fi + Y.se * Z.fi + Z.se * X.fi);
}

void f(ll siz)
{
	cvh.clear();
	
	for(ll i = 1 ; i <= siz ; i++)
	{
		while(cvh.size() >= 2)
		{
			ll now = (ll)cvh.size();
			
			if(ccw(cvh[now - 2], cvh[now - 1], {i, arr[i]}) <= 0)
				cvh.pop_back();
			else
				break;
		}
		
		cvh.push_back({i, arr[i]});
	}
}

int main(void)
{
	fastio
	
	cin >> n >> m;
	
	for(ll i = 1 ; i <= n ; i++)
		cin >> a[i];
	
	for(ll i = 1 ; i <= m ; i++)
		cin >> b[i];
	
	for(ll i = 1 ; i <= n ; i++)
		arr[i] = a[i];
	
	f(n);
	
	for(auto &i : cvh)
		A.push_back(i.fi);
	
	for(ll i = 1 ; i <= m ; i++)
		arr[i] = b[i];
	
	f(m);
	
	for(auto &i : cvh)
		B.push_back(i.fi);
	
	x = 0, y = 0;
	ll sizA = (ll)A.size(), sizB = (ll)B.size();
	
	while(1)
	{
		if(x == sizA - 1 && y == sizB - 1)
			break;
		
		pll gapA, gapB;
		
		gapA = {INF / 2000000000, 1};
		gapB = {INF / 2000000000, 1};
		
		if(x < sizA - 1)
			gapA = {a[A[x + 1]] - a[A[x]], A[x + 1] - A[x]};
		
		if(y < sizB - 1)
			gapB = {b[B[y + 1]] - b[B[y]], B[y + 1] - B[y]};
		
		if(gapA.fi * gapB.se > gapB.fi * gapA.se)
		{
			ans += a[A[x]] * (B[y + 1] - B[y]);
			y++;
		}
		
		else
		{
			ans += b[B[y]] * (A[x + 1] - A[x]);
			x++;
		}
	}
	
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2512 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 6 ms 3012 KB Output is correct
5 Correct 5 ms 2908 KB Output is correct
6 Correct 3 ms 2648 KB Output is correct
7 Correct 13 ms 3392 KB Output is correct
8 Correct 14 ms 3672 KB Output is correct
9 Correct 14 ms 3420 KB Output is correct
10 Correct 14 ms 3420 KB Output is correct
11 Correct 12 ms 3412 KB Output is correct
12 Correct 15 ms 3416 KB Output is correct
13 Correct 14 ms 3420 KB Output is correct
14 Correct 12 ms 3576 KB Output is correct
15 Correct 13 ms 3676 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2392 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2512 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 0 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 6 ms 3012 KB Output is correct
33 Correct 5 ms 2908 KB Output is correct
34 Correct 3 ms 2648 KB Output is correct
35 Correct 13 ms 3392 KB Output is correct
36 Correct 14 ms 3672 KB Output is correct
37 Correct 14 ms 3420 KB Output is correct
38 Correct 14 ms 3420 KB Output is correct
39 Correct 12 ms 3412 KB Output is correct
40 Correct 15 ms 3416 KB Output is correct
41 Correct 14 ms 3420 KB Output is correct
42 Correct 12 ms 3576 KB Output is correct
43 Correct 13 ms 3676 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 0 ms 2396 KB Output is correct
49 Correct 0 ms 2392 KB Output is correct
50 Correct 1 ms 2396 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 0 ms 2396 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 9 ms 3348 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2652 KB Output is correct
58 Correct 3 ms 2776 KB Output is correct
59 Correct 19 ms 4544 KB Output is correct
60 Correct 20 ms 4536 KB Output is correct
61 Correct 19 ms 4700 KB Output is correct
62 Correct 19 ms 4540 KB Output is correct
63 Correct 20 ms 6672 KB Output is correct
64 Correct 24 ms 4564 KB Output is correct
65 Correct 19 ms 4668 KB Output is correct
66 Correct 18 ms 4700 KB Output is correct
67 Correct 18 ms 4696 KB Output is correct