답안 #49866

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
49866 2018-06-04T01:43:51 Z MatheusLealV Candies (JOI18_candies) C++17
100 / 100
619 ms 76196 KB
#include <bits/stdc++.h>
#define inf 200000000000000000
#define N 200050
#define f first
#define s second
using namespace std;
#define int long long
typedef pair<int, int> pii;

int n, k, v[N], ans, t = 0;

set < pii > pq, list;

struct linked_list
{
	int esq[N], dir[N];

	void clear()
	{
		memset(esq, 0, sizeof esq);

		memset(dir, 0, sizeof dir);
	}

	void erase(int p)
	{
		if( p <= 0 || p > n ) return;

		dir[esq[p]] = dir[p];

		esq[dir[p]] = esq[p];
	}

} L;

int32_t main()
{
	ios::sync_with_stdio(false); cin.tie(0);

	cin>>n;

	for(int i = 1; i <= n; i++)
	{
		cin>>v[i];

		L.esq[i] = i - 1;

		L.dir[i] = i + 1;

		pq.insert({-v[i], i});
	}

	for(int i = 1; i <= ((n + 1)/2); i++)
	{
		auto it = pq.begin();

		int x = -(*it).f, id = (*it).s;

		int l = L.esq[id], r = L.dir[id];

		L.erase(l), L.erase(r);

		if(l > 0 && l <= n && r > 0 && r <= n) v[id] = -v[id] + v[l] + v[r];

		else v[id] = -inf;

		pq.erase({-x, id}), pq.erase({-v[l], l}), pq.erase({-v[r], r});

		pq.insert({-v[id], id});

		ans += x;

		cout<<ans<<"\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 4 ms 616 KB Output is correct
3 Correct 3 ms 832 KB Output is correct
4 Correct 3 ms 832 KB Output is correct
5 Correct 4 ms 956 KB Output is correct
6 Correct 3 ms 956 KB Output is correct
7 Correct 3 ms 956 KB Output is correct
8 Correct 4 ms 956 KB Output is correct
9 Correct 3 ms 1076 KB Output is correct
10 Correct 3 ms 1076 KB Output is correct
11 Correct 5 ms 1076 KB Output is correct
12 Correct 4 ms 1076 KB Output is correct
13 Correct 5 ms 1088 KB Output is correct
14 Correct 4 ms 1108 KB Output is correct
15 Correct 3 ms 1128 KB Output is correct
16 Correct 7 ms 1148 KB Output is correct
17 Correct 5 ms 1172 KB Output is correct
18 Correct 5 ms 1316 KB Output is correct
19 Correct 6 ms 1316 KB Output is correct
20 Correct 4 ms 1316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 4 ms 616 KB Output is correct
3 Correct 3 ms 832 KB Output is correct
4 Correct 3 ms 832 KB Output is correct
5 Correct 4 ms 956 KB Output is correct
6 Correct 3 ms 956 KB Output is correct
7 Correct 3 ms 956 KB Output is correct
8 Correct 4 ms 956 KB Output is correct
9 Correct 3 ms 1076 KB Output is correct
10 Correct 3 ms 1076 KB Output is correct
11 Correct 5 ms 1076 KB Output is correct
12 Correct 4 ms 1076 KB Output is correct
13 Correct 5 ms 1088 KB Output is correct
14 Correct 4 ms 1108 KB Output is correct
15 Correct 3 ms 1128 KB Output is correct
16 Correct 7 ms 1148 KB Output is correct
17 Correct 5 ms 1172 KB Output is correct
18 Correct 5 ms 1316 KB Output is correct
19 Correct 6 ms 1316 KB Output is correct
20 Correct 4 ms 1316 KB Output is correct
21 Correct 614 ms 21816 KB Output is correct
22 Correct 619 ms 23824 KB Output is correct
23 Correct 558 ms 25796 KB Output is correct
24 Correct 247 ms 27512 KB Output is correct
25 Correct 224 ms 29220 KB Output is correct
26 Correct 243 ms 31032 KB Output is correct
27 Correct 229 ms 32988 KB Output is correct
28 Correct 205 ms 34868 KB Output is correct
29 Correct 211 ms 36948 KB Output is correct
30 Correct 234 ms 38904 KB Output is correct
31 Correct 232 ms 40732 KB Output is correct
32 Correct 216 ms 42832 KB Output is correct
33 Correct 386 ms 44460 KB Output is correct
34 Correct 387 ms 46188 KB Output is correct
35 Correct 318 ms 48000 KB Output is correct
36 Correct 570 ms 49980 KB Output is correct
37 Correct 578 ms 51912 KB Output is correct
38 Correct 611 ms 53872 KB Output is correct
39 Correct 198 ms 55472 KB Output is correct
40 Correct 268 ms 57380 KB Output is correct
41 Correct 167 ms 59184 KB Output is correct
42 Correct 214 ms 61040 KB Output is correct
43 Correct 185 ms 63040 KB Output is correct
44 Correct 197 ms 64972 KB Output is correct
45 Correct 231 ms 67096 KB Output is correct
46 Correct 235 ms 68920 KB Output is correct
47 Correct 220 ms 71024 KB Output is correct
48 Correct 329 ms 72596 KB Output is correct
49 Correct 292 ms 74444 KB Output is correct
50 Correct 321 ms 76196 KB Output is correct