# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
45133 | 2018-04-11T12:35:08 Z | ikura355 | Candies (JOI18_candies) | C++14 | 197 ms | 13320 KB |
#include<bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; struct node { int x,y; long long val; node(int _x = 0, int _y = 0, long long _val = 0) { x = _x; y = _y; val = _val; } bool operator < (node a) const { return a.val>val; } }; int n; long long a[maxn]; int l[maxn], r[maxn]; long long sum[maxn], lval[maxn], rval[maxn]; priority_queue<node> heap; int main() { scanf("%d",&n); n += 2; for(int i=2;i<=n-1;i++) scanf("%lld",&a[i]); a[1] = a[n] = -1e16; for(int i=1;i<=n;i++) sum[i] = sum[i-1] + a[i]; for(int i=0;i<=n;i++) { l[i] = r[i] = -1; if(i!=0) l[i] = i-1, lval[i] = sum[i]-sum[i-1]; if(i!=n) r[i] = i+1, rval[i] = sum[i+1]-sum[i]; if(i) heap.push(node(i-1,i,sum[i]-sum[i-1])); } int cur = (n-2+1)/2; long long ans = 0; while(!heap.empty() && cur) { node t = heap.top(); heap.pop(); int x = t.x, y = t.y; long long val = t.val; if(r[x]!=y || l[y]!=x) continue; ans += val; int L = l[x], R = r[y]; if(L!=-1 && R!=-1) { long long nval = lval[x] + rval[y] - val; r[L] = R; l[R] = L; rval[L] = lval[R] = nval; heap.push(node(L,R,nval)); } printf("%lld\n",ans); cur--; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 504 KB | Output is correct |
2 | Correct | 4 ms | 612 KB | Output is correct |
3 | Correct | 3 ms | 720 KB | Output is correct |
4 | Correct | 3 ms | 720 KB | Output is correct |
5 | Correct | 3 ms | 720 KB | Output is correct |
6 | Correct | 3 ms | 720 KB | Output is correct |
7 | Correct | 3 ms | 720 KB | Output is correct |
8 | Correct | 3 ms | 776 KB | Output is correct |
9 | Correct | 3 ms | 776 KB | Output is correct |
10 | Correct | 3 ms | 776 KB | Output is correct |
11 | Correct | 3 ms | 776 KB | Output is correct |
12 | Correct | 4 ms | 776 KB | Output is correct |
13 | Correct | 3 ms | 776 KB | Output is correct |
14 | Correct | 3 ms | 776 KB | Output is correct |
15 | Correct | 3 ms | 904 KB | Output is correct |
16 | Correct | 3 ms | 904 KB | Output is correct |
17 | Correct | 3 ms | 904 KB | Output is correct |
18 | Correct | 3 ms | 904 KB | Output is correct |
19 | Correct | 3 ms | 904 KB | Output is correct |
20 | Correct | 3 ms | 904 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 504 KB | Output is correct |
2 | Correct | 4 ms | 612 KB | Output is correct |
3 | Correct | 3 ms | 720 KB | Output is correct |
4 | Correct | 3 ms | 720 KB | Output is correct |
5 | Correct | 3 ms | 720 KB | Output is correct |
6 | Correct | 3 ms | 720 KB | Output is correct |
7 | Correct | 3 ms | 720 KB | Output is correct |
8 | Correct | 3 ms | 776 KB | Output is correct |
9 | Correct | 3 ms | 776 KB | Output is correct |
10 | Correct | 3 ms | 776 KB | Output is correct |
11 | Correct | 3 ms | 776 KB | Output is correct |
12 | Correct | 4 ms | 776 KB | Output is correct |
13 | Correct | 3 ms | 776 KB | Output is correct |
14 | Correct | 3 ms | 776 KB | Output is correct |
15 | Correct | 3 ms | 904 KB | Output is correct |
16 | Correct | 3 ms | 904 KB | Output is correct |
17 | Correct | 3 ms | 904 KB | Output is correct |
18 | Correct | 3 ms | 904 KB | Output is correct |
19 | Correct | 3 ms | 904 KB | Output is correct |
20 | Correct | 3 ms | 904 KB | Output is correct |
21 | Correct | 197 ms | 13188 KB | Output is correct |
22 | Correct | 166 ms | 13188 KB | Output is correct |
23 | Correct | 164 ms | 13188 KB | Output is correct |
24 | Correct | 111 ms | 13188 KB | Output is correct |
25 | Correct | 128 ms | 13192 KB | Output is correct |
26 | Correct | 118 ms | 13192 KB | Output is correct |
27 | Correct | 118 ms | 13192 KB | Output is correct |
28 | Correct | 122 ms | 13192 KB | Output is correct |
29 | Correct | 140 ms | 13216 KB | Output is correct |
30 | Correct | 126 ms | 13216 KB | Output is correct |
31 | Correct | 128 ms | 13216 KB | Output is correct |
32 | Correct | 121 ms | 13216 KB | Output is correct |
33 | Correct | 145 ms | 13216 KB | Output is correct |
34 | Correct | 140 ms | 13216 KB | Output is correct |
35 | Correct | 136 ms | 13240 KB | Output is correct |
36 | Correct | 159 ms | 13240 KB | Output is correct |
37 | Correct | 169 ms | 13292 KB | Output is correct |
38 | Correct | 191 ms | 13292 KB | Output is correct |
39 | Correct | 126 ms | 13320 KB | Output is correct |
40 | Correct | 127 ms | 13320 KB | Output is correct |
41 | Correct | 129 ms | 13320 KB | Output is correct |
42 | Correct | 121 ms | 13320 KB | Output is correct |
43 | Correct | 154 ms | 13320 KB | Output is correct |
44 | Correct | 133 ms | 13320 KB | Output is correct |
45 | Correct | 121 ms | 13320 KB | Output is correct |
46 | Correct | 125 ms | 13320 KB | Output is correct |
47 | Correct | 152 ms | 13320 KB | Output is correct |
48 | Correct | 135 ms | 13320 KB | Output is correct |
49 | Correct | 164 ms | 13320 KB | Output is correct |
50 | Correct | 145 ms | 13320 KB | Output is correct |