Submission #605375

# Submission time Handle Problem Language Result Execution time Memory
605375 2022-07-25T16:37:04 Z Red_Inside Sightseeing in Kyoto (JOI22_kyoto) C++17
100 / 100
663 ms 28948 KB
//
#include <bits/stdc++.h>

#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define all(v) v.begin(), v.end()
#define ld long double
#define ull unsigned long long

using namespace std;
const int maxn=1e6+100,LOG=17,mod=1e9+7;
int block = 226, timer = 0;
const ld EPS = 1e-18;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define bt(i) (1 << (i))
#define int ll
const int inf=2e9;
#define y1 yy
#define prev pre
#define pii pair <int, int>

int n, m, a[maxn], b[maxn];
set <pair <double, pair <pii, int> > > st;
set <int> s[3];
pii pos;

main()
{
	IOS
	cin >> n >> m;
	forn(1, i, n)
	{
		cin >> a[i];
	}
	forn(1, j, m)
	{
		cin >> b[j];
	}
	forn(1, i, n - 1)
	{
		st.insert({(a[i + 1] - a[i]), {{i, i + 1}, 1}});
	}
	forn(1, i, n) s[1].insert(i);
	forn(1, j, m) s[2].insert(j);
	forn(1, i, m - 1)
	{
		st.insert({(b[i + 1] - b[i]), {{i, i + 1}, 2}});
	}
	int ans = 0;
	pos.f = n;
	pos.s = m;
	while(st.size())
	{
		auto it = *st.find(*st.rbegin());
//		cout << "DELETE " << it.s.f.s << " " << it.s.s << " " << it.f << endl;
		st.erase(it);
		if(it.s.s == 1)
		{
			s[1].erase(it.s.f.s);
			auto it2 = s[1].lower_bound(it.s.f.s);
			if(it2 != s[1].end())
			{
				st.erase({1.0 * (a[*it2] - a[it.s.f.s]) / (*it2 - it.s.f.s), 
				{{it.s.f.s, *it2}, 1}});
				st.insert({1.0 * (a[*it2] - a[it.s.f.f]) / (*it2 - it.s.f.f), 
				{{it.s.f.f, *it2}, 1}});
			}
			else
			{
//				cout << "PLUS!!!!!!     " << (pos.s - *s[2].rbegin()) * a[it.s.f.s] << endl;
				ans += (pos.s - *s[2].rbegin()) * a[it.s.f.s];
				pos.s = *s[2].rbegin();
			}
		}
		else
		{
			s[2].erase(it.s.f.s);
			auto it2 = s[2].lower_bound(it.s.f.s);
			if(it2 != s[2].end())
			{
				st.erase({1.0 * (b[*it2] - b[it.s.f.s]) / (*it2 - it.s.f.s), 
				{{it.s.f.s, *it2}, 2}});
				st.insert({1.0 * (b[*it2] - b[it.s.f.f]) / (*it2 - it.s.f.f), 
				{{it.s.f.f, *it2}, 2}});
			}
			else
			{
//				cout << "PLUS!!!!!!   " << (pos.f - *s[1].rbegin()) * b[it.s.f.s] << endl;
				ans += (pos.f - *s[1].rbegin()) * b[it.s.f.s];
				pos.f = *s[1].rbegin();
			}
		}
	}
	if(pos.f != 1) ans += b[1] * (pos.f-1);
	else ans += a[1] * (pos.s-1);
	cout << ans;
}

Compilation message

kyoto.cpp:36:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   36 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 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 340 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 195 ms 11424 KB Output is correct
5 Correct 77 ms 10712 KB Output is correct
6 Correct 49 ms 4684 KB Output is correct
7 Correct 596 ms 27728 KB Output is correct
8 Correct 621 ms 27796 KB Output is correct
9 Correct 603 ms 27720 KB Output is correct
10 Correct 596 ms 27600 KB Output is correct
11 Correct 177 ms 27596 KB Output is correct
12 Correct 599 ms 27724 KB Output is correct
13 Correct 594 ms 27720 KB Output is correct
14 Correct 369 ms 27724 KB Output is correct
15 Correct 138 ms 27832 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 3 ms 596 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 340 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 340 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 195 ms 11424 KB Output is correct
33 Correct 77 ms 10712 KB Output is correct
34 Correct 49 ms 4684 KB Output is correct
35 Correct 596 ms 27728 KB Output is correct
36 Correct 621 ms 27796 KB Output is correct
37 Correct 603 ms 27720 KB Output is correct
38 Correct 596 ms 27600 KB Output is correct
39 Correct 177 ms 27596 KB Output is correct
40 Correct 599 ms 27724 KB Output is correct
41 Correct 594 ms 27720 KB Output is correct
42 Correct 369 ms 27724 KB Output is correct
43 Correct 138 ms 27832 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 340 KB Output is correct
46 Correct 0 ms 332 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 336 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 0 ms 340 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
54 Correct 0 ms 340 KB Output is correct
55 Correct 238 ms 12936 KB Output is correct
56 Correct 2 ms 468 KB Output is correct
57 Correct 11 ms 1620 KB Output is correct
58 Correct 37 ms 4132 KB Output is correct
59 Correct 635 ms 28948 KB Output is correct
60 Correct 637 ms 28864 KB Output is correct
61 Correct 638 ms 28900 KB Output is correct
62 Correct 634 ms 28876 KB Output is correct
63 Correct 147 ms 28844 KB Output is correct
64 Correct 641 ms 28876 KB Output is correct
65 Correct 663 ms 28872 KB Output is correct
66 Correct 210 ms 28876 KB Output is correct
67 Correct 152 ms 28392 KB Output is correct