Submission #48476

# Submission time Handle Problem Language Result Execution time Memory
48476 2018-05-14T09:25:58 Z yp155136 Candies (JOI18_candies) C++14
100 / 100
139 ms 20532 KB
#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;
    }
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
candies.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&cost[i]);
         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 3 ms 696 KB Output is correct
5 Correct 3 ms 712 KB Output is correct
6 Correct 4 ms 800 KB Output is correct
7 Correct 3 ms 944 KB Output is correct
8 Correct 3 ms 944 KB Output is correct
9 Correct 3 ms 944 KB Output is correct
10 Correct 3 ms 944 KB Output is correct
11 Correct 3 ms 952 KB Output is correct
12 Correct 3 ms 976 KB Output is correct
13 Correct 3 ms 1020 KB Output is correct
14 Correct 3 ms 1040 KB Output is correct
15 Correct 3 ms 1076 KB Output is correct
16 Correct 3 ms 1096 KB Output is correct
17 Correct 3 ms 1120 KB Output is correct
18 Correct 3 ms 1140 KB Output is correct
19 Correct 2 ms 1156 KB Output is correct
20 Correct 3 ms 1176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 3 ms 696 KB Output is correct
5 Correct 3 ms 712 KB Output is correct
6 Correct 4 ms 800 KB Output is correct
7 Correct 3 ms 944 KB Output is correct
8 Correct 3 ms 944 KB Output is correct
9 Correct 3 ms 944 KB Output is correct
10 Correct 3 ms 944 KB Output is correct
11 Correct 3 ms 952 KB Output is correct
12 Correct 3 ms 976 KB Output is correct
13 Correct 3 ms 1020 KB Output is correct
14 Correct 3 ms 1040 KB Output is correct
15 Correct 3 ms 1076 KB Output is correct
16 Correct 3 ms 1096 KB Output is correct
17 Correct 3 ms 1120 KB Output is correct
18 Correct 3 ms 1140 KB Output is correct
19 Correct 2 ms 1156 KB Output is correct
20 Correct 3 ms 1176 KB Output is correct
21 Correct 135 ms 10932 KB Output is correct
22 Correct 132 ms 12960 KB Output is correct
23 Correct 132 ms 14888 KB Output is correct
24 Correct 102 ms 16560 KB Output is correct
25 Correct 103 ms 18508 KB Output is correct
26 Correct 105 ms 20248 KB Output is correct
27 Correct 128 ms 20328 KB Output is correct
28 Correct 119 ms 20336 KB Output is correct
29 Correct 120 ms 20336 KB Output is correct
30 Correct 129 ms 20468 KB Output is correct
31 Correct 121 ms 20468 KB Output is correct
32 Correct 123 ms 20468 KB Output is correct
33 Correct 121 ms 20468 KB Output is correct
34 Correct 126 ms 20468 KB Output is correct
35 Correct 125 ms 20468 KB Output is correct
36 Correct 139 ms 20468 KB Output is correct
37 Correct 130 ms 20468 KB Output is correct
38 Correct 139 ms 20468 KB Output is correct
39 Correct 104 ms 20468 KB Output is correct
40 Correct 109 ms 20468 KB Output is correct
41 Correct 110 ms 20468 KB Output is correct
42 Correct 124 ms 20468 KB Output is correct
43 Correct 125 ms 20468 KB Output is correct
44 Correct 124 ms 20468 KB Output is correct
45 Correct 131 ms 20468 KB Output is correct
46 Correct 125 ms 20468 KB Output is correct
47 Correct 123 ms 20468 KB Output is correct
48 Correct 127 ms 20468 KB Output is correct
49 Correct 132 ms 20532 KB Output is correct
50 Correct 131 ms 20532 KB Output is correct