| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 202253 | quocnguyen1012 | Candies (JOI18_candies) | C++14 | 6 ms | 504 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
const int inf = 2e9 + 5;
int N, a[maxn], prf[maxn], nxt[maxn];
priority_queue<pair<int, int>> pq;
bool del(int idx)
{
prf[nxt[idx]] = prf[idx];
nxt[prf[idx]] = nxt[idx];
}
signed main(void)
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen("A.INP", "r")){
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
}
cin >> N;
for (int i = 1; i <= N; ++i){
cin >> a[i];
prf[i] = i - 1;
nxt[i] = i + 1;
pq.push(mp(a[i], i));
}
ll res = 0;
for (int i = 1; i <= (N + 1) / 2; ++i){
while (pq.size() && a[pq.top().se] != pq.top().fi) pq.pop();
auto now = pq.top(); pq.pop();
res += now.fi;
cout << res << '\n';
int pos = now.se;
a[pos] = max(-inf, a[prf[pos]] + a[nxt[pos]] - a[pos]);
int L = prf[pos], R = nxt[pos];
del(L); del(R);
a[L] = a[R] = -inf;
pq.push(mp(a[pos], pos));
}
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
