답안 #1076731

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1076731 2024-08-26T16:01:54 Z vjudge1 Candies (JOI18_candies) C++17
100 / 100
80 ms 14268 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 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 476 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 656 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 1 ms 476 KB Output is correct
8 Correct 1 ms 856 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 604 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 604 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 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 476 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 656 KB Output is correct
6 Correct 2 ms 860 KB Output is correct
7 Correct 1 ms 476 KB Output is correct
8 Correct 1 ms 856 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 604 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 604 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 14016 KB Output is correct
22 Correct 70 ms 14012 KB Output is correct
23 Correct 70 ms 13960 KB Output is correct
24 Correct 50 ms 14016 KB Output is correct
25 Correct 50 ms 13936 KB Output is correct
26 Correct 48 ms 13828 KB Output is correct
27 Correct 52 ms 14024 KB Output is correct
28 Correct 51 ms 14020 KB Output is correct
29 Correct 54 ms 14020 KB Output is correct
30 Correct 60 ms 14032 KB Output is correct
31 Correct 51 ms 14016 KB Output is correct
32 Correct 53 ms 14268 KB Output is correct
33 Correct 56 ms 13756 KB Output is correct
34 Correct 61 ms 13764 KB Output is correct
35 Correct 59 ms 14012 KB Output is correct
36 Correct 73 ms 13948 KB Output is correct
37 Correct 75 ms 14016 KB Output is correct
38 Correct 80 ms 14140 KB Output is correct
39 Correct 48 ms 14012 KB Output is correct
40 Correct 57 ms 13868 KB Output is correct
41 Correct 56 ms 14012 KB Output is correct
42 Correct 55 ms 14164 KB Output is correct
43 Correct 58 ms 14020 KB Output is correct
44 Correct 63 ms 14012 KB Output is correct
45 Correct 62 ms 14016 KB Output is correct
46 Correct 57 ms 14020 KB Output is correct
47 Correct 54 ms 14016 KB Output is correct
48 Correct 59 ms 13756 KB Output is correct
49 Correct 58 ms 13760 KB Output is correct
50 Correct 59 ms 13756 KB Output is correct