답안 #961011

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
961011 2024-04-11T11:29:49 Z pcc Candies (JOI18_candies) C++17
100 / 100
83 ms 20420 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>

const ll mxn = 4e5+10;

struct node{
	int pl,pr;
	ll val;
	node(){}
};

node lst[mxn];
int ppp = 0;

int newnode(){
	return ++ppp;
}

int N;
ll arr[mxn];
ll ans[mxn];
priority_queue<pll,vector<pll>,less<pll>> pq;
bitset<mxn> dead;

void del(int now){
	int ls = lst[now].pl,rs = lst[now].pr;
	lst[ls].pr = rs;
	lst[rs].pl = ls;
	dead[now] = true;
	return;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N;
	int pre = 0;
	for(int i = 1;i<=N;i++){
		cin>>arr[i];
		int tmp = newnode();
		lst[tmp].pl = pre;
		lst[pre].pr = tmp;
		lst[tmp].val = arr[i];
		pre = tmp;
	}
	for(int i = 1;i<=N;i++){
		pq.push(pll(lst[i].val,i));
	}
	for(int i = 1;i<=(N+1)/2;i++){
		while(dead[pq.top().sc])pq.pop();
		ans[i] = ans[i-1];
		auto now = pq.top().sc;pq.pop();
		ans[i] += lst[now].val;
		int ls = lst[now].pl,rs = lst[now].pr;
		del(now);
		if(ls)del(ls);
		if(rs)del(rs);
		if(!ls||!rs)continue;
		int tmp = newnode();
		lst[tmp].val = lst[ls].val+lst[rs].val-lst[now].val;
		ls = lst[ls].pl,rs = lst[rs].pr;
		lst[tmp].pl = ls;lst[ls].pr = tmp;
		lst[tmp].pr = rs;lst[rs].pl = tmp;
		pq.push(pll(lst[tmp].val,tmp));
	}
	for(int i = 1;i<=(N+1)/2;i++)cout<<ans[i]<<'\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6724 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 1 ms 6640 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6488 KB Output is correct
8 Correct 2 ms 6488 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6624 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6628 KB Output is correct
14 Correct 2 ms 6488 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6724 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 1 ms 6640 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6488 KB Output is correct
8 Correct 2 ms 6488 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6624 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6628 KB Output is correct
14 Correct 2 ms 6488 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 71 ms 20328 KB Output is correct
22 Correct 83 ms 19584 KB Output is correct
23 Correct 68 ms 19412 KB Output is correct
24 Correct 61 ms 19540 KB Output is correct
25 Correct 58 ms 19400 KB Output is correct
26 Correct 65 ms 19648 KB Output is correct
27 Correct 64 ms 20420 KB Output is correct
28 Correct 67 ms 19640 KB Output is correct
29 Correct 73 ms 20416 KB Output is correct
30 Correct 65 ms 19652 KB Output is correct
31 Correct 64 ms 20232 KB Output is correct
32 Correct 67 ms 19448 KB Output is correct
33 Correct 65 ms 19228 KB Output is correct
34 Correct 66 ms 19228 KB Output is correct
35 Correct 67 ms 19256 KB Output is correct
36 Correct 71 ms 19420 KB Output is correct
37 Correct 73 ms 20072 KB Output is correct
38 Correct 77 ms 19616 KB Output is correct
39 Correct 57 ms 19400 KB Output is correct
40 Correct 57 ms 20156 KB Output is correct
41 Correct 56 ms 20200 KB Output is correct
42 Correct 69 ms 19760 KB Output is correct
43 Correct 62 ms 19444 KB Output is correct
44 Correct 71 ms 19628 KB Output is correct
45 Correct 63 ms 19640 KB Output is correct
46 Correct 62 ms 19448 KB Output is correct
47 Correct 65 ms 19900 KB Output is correct
48 Correct 70 ms 19808 KB Output is correct
49 Correct 66 ms 19388 KB Output is correct
50 Correct 73 ms 19220 KB Output is correct