답안 #1087209

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087209 2024-09-12T09:36:48 Z coldbr3w Candies (JOI18_candies) C++17
100 / 100
75 ms 14272 KB
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<long long, long long>
#define pb push_back
#define F first
#define S second  
#define all(x) (x).begin(), (x).end()

const ll N = 2e5 + 100;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll block = 350;
ll a[N], prv[N], nxt[N], del[N], ans[N];
ll n;
struct cmp{
	bool operator()(const pll &a, const pll &b){
		return a.S < b.S;
	}
};
void to_thic_cau(){ 
	cin >> n;
	priority_queue<pll, vector<pll>, cmp>q;
	for(int i = 1; i <= n;i++){
		cin >> a[i];
		prv[i] = i - 1, nxt[i] = i + 1;
		q.push({i, a[i]});
	}
	prv[n+1] = n, nxt[0] = 1, a[0] = a[n+1] = -inf;
	ll cur = (n + 1) / 2, cnt = 0, res = 0;
	while(cnt < cur){
		if(!q.size()) break;
		ll i = q.top().F, val = q.top().S; q.pop();
		if(!del[i] && i > 0 && i <= n){
			del[prv[i]] = del[nxt[i]] = 1;
			res += val;
			a[i] = a[prv[i]] + a[nxt[i]] - val;
			q.push({i, a[i]});
			nxt[i] = nxt[nxt[i]]; prv[i] = prv[prv[i]];
			nxt[prv[i]] = i;
			prv[nxt[i]] = i;
			cnt++;
		}
		ans[cnt] = max(ans[cnt], res);
	}
	for(int i = 1; i <= cur;i++) cout << ans[i] << ' ';
	cout << '\n';
}     

signed main()   
{  
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll tc = 1;
	//cin >> tc;
	while(tc--) to_thic_cau();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 636 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 612 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 636 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 612 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 73 ms 14272 KB Output is correct
22 Correct 75 ms 14016 KB Output is correct
23 Correct 68 ms 14272 KB Output is correct
24 Correct 48 ms 14016 KB Output is correct
25 Correct 48 ms 13860 KB Output is correct
26 Correct 48 ms 14016 KB Output is correct
27 Correct 51 ms 14016 KB Output is correct
28 Correct 50 ms 14012 KB Output is correct
29 Correct 50 ms 14192 KB Output is correct
30 Correct 54 ms 14012 KB Output is correct
31 Correct 54 ms 14104 KB Output is correct
32 Correct 50 ms 14124 KB Output is correct
33 Correct 57 ms 13756 KB Output is correct
34 Correct 57 ms 14108 KB Output is correct
35 Correct 55 ms 14016 KB Output is correct
36 Correct 70 ms 14152 KB Output is correct
37 Correct 70 ms 13952 KB Output is correct
38 Correct 70 ms 14012 KB Output is correct
39 Correct 55 ms 14012 KB Output is correct
40 Correct 49 ms 14016 KB Output is correct
41 Correct 49 ms 14016 KB Output is correct
42 Correct 50 ms 14004 KB Output is correct
43 Correct 56 ms 14012 KB Output is correct
44 Correct 53 ms 14020 KB Output is correct
45 Correct 54 ms 14016 KB Output is correct
46 Correct 50 ms 14144 KB Output is correct
47 Correct 49 ms 14016 KB Output is correct
48 Correct 56 ms 13844 KB Output is correct
49 Correct 55 ms 13976 KB Output is correct
50 Correct 55 ms 13760 KB Output is correct