# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
48476 | yp155136 | Candies (JOI18_candies) | C++14 | 139 ms | 20532 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> pii;
#define F first
#define S second
const int N = 200006;
const LL INF = (1LL<<40);
bool vis[N];
LL cost[N];
int lc[N];
int rc[N];
int main ()
{
int n;
scanf("%d",&n);
priority_queue<pii> pq;
for (int i=1;n>=i;i++)
{
scanf("%lld",&cost[i]);
lc[i] = i-1;
rc[i] = i+1;
pq.push(make_pair(cost[i],i));
}
cost[0] = cost[n+1] = -INF;
LL tot=0;
int cnt=(n+1)/2;
while (!pq.empty())
{
pii p=pq.top();
pq.pop();
if (vis[p.S]) continue;
tot += p.F;
LL newcost = cost[ lc[p.S] ] + cost[ rc[p.S] ] - cost[p.S];
vis[ lc[p.S] ] = vis[ rc[p.S] ] = true;
lc[p.S] = lc[ lc[p.S] ];
rc[p.S] = rc[ rc[p.S] ];
rc[ lc[p.S] ] = p.S;
lc[ rc[p.S] ] = p.S;
cost[p.S] = newcost;
printf("%lld\n",tot);
--cnt;
pq.push(make_pair(cost[p.S],p.S));
if (!cnt) break;
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |