# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
133902 | duality | Candies (JOI18_candies) | C++11 | 169 ms | 11052 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef long long int LLI;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
int A[200000];
int l[200001],r[200001];
LLI rs[200001];
priority_queue<pair<LLI,pii> > H;
int main() {
int i;
int N;
scanf("%d",&N);
for (i = 0; i < N; i++) scanf("%d",&A[i]);
LLI ans = 0;
for (i = 0; i <= N; i++) {
l[i] = i-1,r[i] = i+1;
if (i < N) rs[i] = A[i],H.push(mp(A[i],mp(i,i+1)));
}
while (!H.empty()) {
int a = H.top().second.first,b = H.top().second.second;
LLI d = H.top().first;
H.pop();
if ((r[a] != b) || (l[b] != a)) continue;
ans += d,printf("%lld\n",ans);
if (l[a] != -1) r[l[a]] = r[b];
if (r[b] != N+1) l[r[b]] = l[a];
if ((l[a] != -1) && (r[b] != N+1)) {
H.push(mp(rs[l[a]]-d+rs[b],mp(l[a],r[b])));
rs[l[a]] = rs[l[a]]-d+rs[b];
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |