# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
61660 | 2018-07-26T09:49:49 Z | cki86201 | Candies (JOI18_candies) | C++11 | 275 ms | 9460 KB |
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <memory.h> #include <math.h> #include <assert.h> #include <queue> #include <map> #include <set> #include <string> #include <algorithm> #include <iostream> #include <functional> #include <unordered_map> #include <unordered_set> #include <list> #include <bitset> using namespace std; typedef long long ll; #define Fi first #define Se second #define pb(x) push_back(x) #define szz(x) ((int)(x).size()) #define rep(i, n) for(int i=0;i<n;i++) #define all(x) (x).begin(), (x).end() typedef tuple<int, int, int> t3; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef long double ldouble; int N; ll A[200020]; int nxt[200020], pre[200020], chk[200020]; int main() { scanf("%d", &N); for(int i=1;i<=N;i++) scanf("%lld", A+i); for(int i=1;i<=N+1;i++) pre[i] = i-1; for(int i=0;i<=N;i++) nxt[i] = i+1; nxt[N+1] = pre[0] = -1; A[0] = A[N+1] = -1e18; priority_queue <pll> pq; ll ans = 0; for(int i=1;i<=N;i++) pq.push(pll(A[i], i)); for(int i=1;i<=(N+1)/2;i++) { pll t = pq.top(); pq.pop(); if(chk[t.Se]) { --i; continue; } ans += t.Fi; int idx = (int)t.Se; int pr = pre[idx]; int nx = nxt[idx]; chk[pr] = chk[nx] = 1; A[idx] = -A[idx] + A[pr] + A[nx]; pq.push(pll(A[idx], idx)); nxt[idx] = nxt[nx]; if(nxt[nx] != -1) pre[nxt[nx]] = idx; pre[idx] = pre[pr]; if(pre[pr] != -1) nxt[pre[pr]] = idx; printf("%lld\n", ans); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 504 KB | Output is correct |
2 | Correct | 5 ms | 632 KB | Output is correct |
3 | Correct | 4 ms | 664 KB | Output is correct |
4 | Correct | 4 ms | 664 KB | Output is correct |
5 | Correct | 4 ms | 700 KB | Output is correct |
6 | Correct | 4 ms | 700 KB | Output is correct |
7 | Correct | 4 ms | 700 KB | Output is correct |
8 | Correct | 3 ms | 700 KB | Output is correct |
9 | Correct | 4 ms | 700 KB | Output is correct |
10 | Correct | 5 ms | 736 KB | Output is correct |
11 | Correct | 3 ms | 736 KB | Output is correct |
12 | Correct | 3 ms | 736 KB | Output is correct |
13 | Correct | 4 ms | 800 KB | Output is correct |
14 | Correct | 4 ms | 800 KB | Output is correct |
15 | Correct | 4 ms | 800 KB | Output is correct |
16 | Correct | 5 ms | 800 KB | Output is correct |
17 | Correct | 4 ms | 800 KB | Output is correct |
18 | Correct | 3 ms | 800 KB | Output is correct |
19 | Correct | 5 ms | 800 KB | Output is correct |
20 | Correct | 4 ms | 800 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 504 KB | Output is correct |
2 | Correct | 5 ms | 632 KB | Output is correct |
3 | Correct | 4 ms | 664 KB | Output is correct |
4 | Correct | 4 ms | 664 KB | Output is correct |
5 | Correct | 4 ms | 700 KB | Output is correct |
6 | Correct | 4 ms | 700 KB | Output is correct |
7 | Correct | 4 ms | 700 KB | Output is correct |
8 | Correct | 3 ms | 700 KB | Output is correct |
9 | Correct | 4 ms | 700 KB | Output is correct |
10 | Correct | 5 ms | 736 KB | Output is correct |
11 | Correct | 3 ms | 736 KB | Output is correct |
12 | Correct | 3 ms | 736 KB | Output is correct |
13 | Correct | 4 ms | 800 KB | Output is correct |
14 | Correct | 4 ms | 800 KB | Output is correct |
15 | Correct | 4 ms | 800 KB | Output is correct |
16 | Correct | 5 ms | 800 KB | Output is correct |
17 | Correct | 4 ms | 800 KB | Output is correct |
18 | Correct | 3 ms | 800 KB | Output is correct |
19 | Correct | 5 ms | 800 KB | Output is correct |
20 | Correct | 4 ms | 800 KB | Output is correct |
21 | Correct | 221 ms | 9328 KB | Output is correct |
22 | Correct | 230 ms | 9328 KB | Output is correct |
23 | Correct | 239 ms | 9392 KB | Output is correct |
24 | Correct | 141 ms | 9460 KB | Output is correct |
25 | Correct | 175 ms | 9460 KB | Output is correct |
26 | Correct | 221 ms | 9460 KB | Output is correct |
27 | Correct | 163 ms | 9460 KB | Output is correct |
28 | Correct | 211 ms | 9460 KB | Output is correct |
29 | Correct | 173 ms | 9460 KB | Output is correct |
30 | Correct | 232 ms | 9460 KB | Output is correct |
31 | Correct | 172 ms | 9460 KB | Output is correct |
32 | Correct | 240 ms | 9460 KB | Output is correct |
33 | Correct | 195 ms | 9460 KB | Output is correct |
34 | Correct | 207 ms | 9460 KB | Output is correct |
35 | Correct | 238 ms | 9460 KB | Output is correct |
36 | Correct | 260 ms | 9460 KB | Output is correct |
37 | Correct | 205 ms | 9460 KB | Output is correct |
38 | Correct | 221 ms | 9460 KB | Output is correct |
39 | Correct | 199 ms | 9460 KB | Output is correct |
40 | Correct | 134 ms | 9460 KB | Output is correct |
41 | Correct | 164 ms | 9460 KB | Output is correct |
42 | Correct | 227 ms | 9460 KB | Output is correct |
43 | Correct | 275 ms | 9460 KB | Output is correct |
44 | Correct | 234 ms | 9460 KB | Output is correct |
45 | Correct | 250 ms | 9460 KB | Output is correct |
46 | Correct | 241 ms | 9460 KB | Output is correct |
47 | Correct | 202 ms | 9460 KB | Output is correct |
48 | Correct | 194 ms | 9460 KB | Output is correct |
49 | Correct | 262 ms | 9460 KB | Output is correct |
50 | Correct | 204 ms | 9460 KB | Output is correct |