답안 #711992

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
711992 2023-03-17T21:40:33 Z tutis Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
341 ms 64964 KB
/*input
6
1 2
0 0
2 0
0 0
0 0
0 1

*/
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template<typename A, typename B>
using omap = tree <A, B, less<A>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename A>
using oset = tree <A, null_type, less<A>, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod = 1e9 + 7;
ll ran(ll a, ll b)
{
	//return a + (ll)(rng() % (b - a + 1));
	return uniform_int_distribution<ll>(a, b)(rng);
}
ll power(ll x, ll p)
{
	if (abs(x) >= mod)
		x %= mod;
	if (x < 0)
		x += mod;
	if (abs(p) >= mod - 1)
		p %= mod - 1;
	if (p < 0)
		p += mod - 1;
	ll r = 1;
	while (p)
	{
		if (p % 2)
			r = (r * x) % mod;
		x = (x * x) % mod;
		p /= 2;
	}
	return r;
}
void solve()
{
	int N;
	cin >> N;
	int a[N];
	for (int i = 0; i < N; i++)
	{
		int f, b;
		cin >> f >> b;
		a[i] = f - b;
	}
	map<ll, ll>S;
	ll F = 1e6;
	ll pr = -5e11;
	S[0] = F;
	S[pr] = -F;
	ll v0 = F * -pr;
	ll sh = 0;
	auto f = [&](map<ll, ll>M, ll v0, ll x)->ll
	{
		while ((--M.end())->first >= x)
			M.erase(--M.end());
		M[x] = 0;
		ll sl = 0;
		while (M.size() >= 2)
		{
			pair<ll, ll>x = *M.begin();
			sl += x.second;
			M.erase(M.begin());
			v0 += (M.begin()->first - x.first) * sl;
		}
		return v0;
	};
	for (int i = 0; i < N; i++)
	{
		sh += a[i];
		S[pr]--;
		S[sh] += 2;
		auto it = --S.end();
		if (it->second == 1)
			S.erase(it);
		else
			it->second--;
		v0 += abs(pr - sh);
	}
	cout << f(S, v0, sh) << "\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 20 ms 4552 KB Output is correct
5 Correct 38 ms 7280 KB Output is correct
6 Correct 85 ms 10612 KB Output is correct
7 Correct 279 ms 64964 KB Output is correct
8 Correct 202 ms 27976 KB Output is correct
9 Correct 341 ms 52316 KB Output is correct
10 Correct 62 ms 4160 KB Output is correct
11 Correct 56 ms 4216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 20 ms 4552 KB Output is correct
5 Correct 38 ms 7280 KB Output is correct
6 Correct 85 ms 10612 KB Output is correct
7 Correct 279 ms 64964 KB Output is correct
8 Correct 202 ms 27976 KB Output is correct
9 Correct 341 ms 52316 KB Output is correct
10 Correct 62 ms 4160 KB Output is correct
11 Correct 56 ms 4216 KB Output is correct
12 Correct 54 ms 9220 KB Output is correct
13 Correct 133 ms 20964 KB Output is correct
14 Correct 331 ms 62024 KB Output is correct
15 Correct 242 ms 48848 KB Output is correct
16 Correct 287 ms 37196 KB Output is correct
17 Correct 60 ms 4176 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 3 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 20 ms 4552 KB Output is correct
12 Correct 38 ms 7280 KB Output is correct
13 Correct 85 ms 10612 KB Output is correct
14 Correct 279 ms 64964 KB Output is correct
15 Correct 202 ms 27976 KB Output is correct
16 Correct 341 ms 52316 KB Output is correct
17 Correct 62 ms 4160 KB Output is correct
18 Correct 56 ms 4216 KB Output is correct
19 Correct 54 ms 9220 KB Output is correct
20 Correct 133 ms 20964 KB Output is correct
21 Correct 331 ms 62024 KB Output is correct
22 Correct 242 ms 48848 KB Output is correct
23 Correct 287 ms 37196 KB Output is correct
24 Correct 60 ms 4176 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 632 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 49 ms 10260 KB Output is correct
34 Correct 131 ms 24272 KB Output is correct
35 Correct 240 ms 39588 KB Output is correct
36 Correct 279 ms 37856 KB Output is correct
37 Correct 245 ms 44616 KB Output is correct
38 Correct 216 ms 40316 KB Output is correct
39 Correct 125 ms 20808 KB Output is correct
40 Correct 148 ms 28440 KB Output is correct
41 Correct 56 ms 4176 KB Output is correct
42 Correct 54 ms 4172 KB Output is correct
43 Correct 52 ms 4168 KB Output is correct
44 Correct 55 ms 4304 KB Output is correct
45 Correct 259 ms 40648 KB Output is correct
46 Correct 145 ms 17028 KB Output is correct
47 Correct 141 ms 29044 KB Output is correct