답안 #366849

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
366849 2021-02-15T12:06:18 Z Rainbowbunny Candies (JOI18_candies) C++17
100 / 100
389 ms 19660 KB
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <chrono>
#include <random>
#include <bitset>
#include <utility>
 
int n;
int l[200005], r[200005];
long long a[200005];
std::set <std::pair <long long, int> > S;
 
int main()
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);
	std::cin >> n;
	a[0] = -1e18;
	a[n + 1] = -1e18;
	for(int i = 1; i <= n; i++)
	{
		std::cin >> a[i];
		S.insert(std::make_pair(-a[i], i));
		l[i] = i - 1;
		r[i] = i + 1;
	}
	long long ans = 0;
	for(int i = 1; i <= (n + 1) / 2; i++)
	{
		int id = (*S.begin()).second;
		S.erase(S.begin());
		int left = l[id], right = r[id];
		if(left)
		{
			S.erase(std::make_pair(-a[left], left));
		}
		if(right != n + 1)
		{
			S.erase(std::make_pair(-a[right], right));
		}
		ans += a[id];
		if(left != 0)
		{
			r[l[left]] = id;
			l[id] = l[left];
		}
		if(right != n + 1)
		{
			l[r[right]] = id;
			r[id] = r[right];
		}
		a[id] = a[left] + a[right] - a[id];
		S.insert(std::make_pair(-a[id], id));
		std::cout << ans << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 2 ms 620 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 2 ms 620 KB Output is correct
19 Correct 2 ms 620 KB Output is correct
20 Correct 2 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 2 ms 620 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 2 ms 620 KB Output is correct
18 Correct 2 ms 620 KB Output is correct
19 Correct 2 ms 620 KB Output is correct
20 Correct 2 ms 620 KB Output is correct
21 Correct 389 ms 19328 KB Output is correct
22 Correct 376 ms 19436 KB Output is correct
23 Correct 376 ms 19436 KB Output is correct
24 Correct 149 ms 19308 KB Output is correct
25 Correct 150 ms 19308 KB Output is correct
26 Correct 149 ms 19308 KB Output is correct
27 Correct 159 ms 19456 KB Output is correct
28 Correct 166 ms 19564 KB Output is correct
29 Correct 161 ms 19564 KB Output is correct
30 Correct 173 ms 19564 KB Output is correct
31 Correct 173 ms 19436 KB Output is correct
32 Correct 173 ms 19436 KB Output is correct
33 Correct 263 ms 19180 KB Output is correct
34 Correct 263 ms 19308 KB Output is correct
35 Correct 262 ms 19308 KB Output is correct
36 Correct 376 ms 19564 KB Output is correct
37 Correct 380 ms 19456 KB Output is correct
38 Correct 377 ms 19412 KB Output is correct
39 Correct 148 ms 19308 KB Output is correct
40 Correct 145 ms 19308 KB Output is correct
41 Correct 145 ms 19396 KB Output is correct
42 Correct 162 ms 19580 KB Output is correct
43 Correct 160 ms 19564 KB Output is correct
44 Correct 160 ms 19492 KB Output is correct
45 Correct 182 ms 19660 KB Output is correct
46 Correct 175 ms 19436 KB Output is correct
47 Correct 179 ms 19564 KB Output is correct
48 Correct 258 ms 19308 KB Output is correct
49 Correct 253 ms 19308 KB Output is correct
50 Correct 254 ms 19308 KB Output is correct