답안 #711997

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
711997 2023-03-17T22:16:33 Z tutis Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
174 ms 22368 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;
	}
	priority_queue<pair<ll, ll>>S;
	ll F = 1e6;
	ll pr = -5e11;
	S.push({pr, -F});
	S.push({0, F});
	ll v0 = F * -pr;
	ll sh = 0;
	ll sl = 0;
	for (int i = 0; i < N; i++)
	{
		sh += a[i];
		sl--;
		S.push({sh, 2});
		if (S.top().second == 1)
			S.pop();
		else
		{
			((pair<ll, ll>*)&S.top())->second--;
			// pair<ll, ll>x = S.top();
			// S.pop();
			// x.second--;
			// S.push(x);
		}
		v0 += abs(pr - sh);
	}
	while (S.top().first >= sh)
		S.pop();
	S.push({sh, 0});
	vector<pair<ll, ll>>V;
	while (!S.empty())
	{
		V.push_back(S.top());
		S.pop();
	}
	reverse(V.begin(), V.end());
	for (int i = 0; i + 1 < V.size(); i++)
	{
		sl += V[i].second;
		v0 += (V[i + 1].first - V[i].first) * sl;
	}
	cout << v0 << "\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve();
}

Compilation message

bulves.cpp: In function 'void solve()':
bulves.cpp:97:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |  for (int i = 0; i + 1 < V.size(); i++)
      |                  ~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 13 ms 1668 KB Output is correct
5 Correct 24 ms 2372 KB Output is correct
6 Correct 72 ms 3428 KB Output is correct
7 Correct 172 ms 21552 KB Output is correct
8 Correct 112 ms 10572 KB Output is correct
9 Correct 146 ms 20308 KB Output is correct
10 Correct 93 ms 6468 KB Output is correct
11 Correct 91 ms 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 13 ms 1668 KB Output is correct
5 Correct 24 ms 2372 KB Output is correct
6 Correct 72 ms 3428 KB Output is correct
7 Correct 172 ms 21552 KB Output is correct
8 Correct 112 ms 10572 KB Output is correct
9 Correct 146 ms 20308 KB Output is correct
10 Correct 93 ms 6468 KB Output is correct
11 Correct 91 ms 6488 KB Output is correct
12 Correct 35 ms 2968 KB Output is correct
13 Correct 85 ms 5700 KB Output is correct
14 Correct 174 ms 21172 KB Output is correct
15 Correct 112 ms 10568 KB Output is correct
16 Correct 134 ms 9668 KB Output is correct
17 Correct 127 ms 14780 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 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 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 212 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 340 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 340 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 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 212 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 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 13 ms 1668 KB Output is correct
12 Correct 24 ms 2372 KB Output is correct
13 Correct 72 ms 3428 KB Output is correct
14 Correct 172 ms 21552 KB Output is correct
15 Correct 112 ms 10572 KB Output is correct
16 Correct 146 ms 20308 KB Output is correct
17 Correct 93 ms 6468 KB Output is correct
18 Correct 91 ms 6488 KB Output is correct
19 Correct 35 ms 2968 KB Output is correct
20 Correct 85 ms 5700 KB Output is correct
21 Correct 174 ms 21172 KB Output is correct
22 Correct 112 ms 10568 KB Output is correct
23 Correct 134 ms 9668 KB Output is correct
24 Correct 127 ms 14780 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 34 ms 3360 KB Output is correct
34 Correct 101 ms 9916 KB Output is correct
35 Correct 163 ms 12404 KB Output is correct
36 Correct 129 ms 12236 KB Output is correct
37 Correct 149 ms 15656 KB Output is correct
38 Correct 144 ms 12292 KB Output is correct
39 Correct 117 ms 19468 KB Output is correct
40 Correct 102 ms 11748 KB Output is correct
41 Correct 98 ms 12232 KB Output is correct
42 Correct 109 ms 12220 KB Output is correct
43 Correct 107 ms 12260 KB Output is correct
44 Correct 117 ms 12224 KB Output is correct
45 Correct 155 ms 12348 KB Output is correct
46 Correct 128 ms 22368 KB Output is correct
47 Correct 95 ms 11044 KB Output is correct