Submission #58147

# Submission time Handle Problem Language Result Execution time Memory
58147 2018-07-17T04:14:30 Z King Suryal(#1687) Candies (JOI18_candies) C++11
100 / 100
455 ms 67748 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

struct linkedList {
    linkedList *l, *r;
    llong x;
    bool ch;
} ls[200000];

struct cmp {
    bool operator()(linkedList *x, linkedList *y) {
        return x->x < y->x;
    }
};

int n;
int a[200000];
int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", a + i);
        ls[i].x = a[i];
    }
    for (int i = 1; i < n; ++i) ls[i].l = ls + (i - 1), ls[i - 1].r = ls + i;
    priority_queue<linkedList *, vector<linkedList *>, cmp> pq;
    for (int i = 0; i < n; ++i) {
        pq.push(ls + i);
    }
    
    llong ans = 0;
    for (int i = 0; i < (n + 1) / 2; ++i) {
        linkedList *x;
        do {
            x = pq.top();
            pq.pop();
        } while (x->ch);
        ans += x->x;
        printf("%lld\n", ans);
        if (x->l && x->r) {
            x->x = x->l->x + x->r->x - x->x;
            x->l->ch = 1;
            x->r->ch = 1;
            if (x->l->l) x->l->l->r = x;
            if (x->r->r) x->r->r->l = x;
            x->l = x->l->l;
            x->r = x->r->r;
            pq.push(x);
        }
        else if (x->l) {
            x->l->ch = 1;
            if (x->l->l) x->l->l->r = 0;
        }
        else if (x->r) {
            x->r->ch = 1;
            if (x->r->r) x->r->r->l = 0;
        }
    }
	return 0;
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
candies.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", a + i);
         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 468 KB Output is correct
2 Correct 4 ms 616 KB Output is correct
3 Correct 4 ms 760 KB Output is correct
4 Correct 3 ms 868 KB Output is correct
5 Correct 3 ms 868 KB Output is correct
6 Correct 3 ms 928 KB Output is correct
7 Correct 3 ms 964 KB Output is correct
8 Correct 3 ms 984 KB Output is correct
9 Correct 3 ms 1004 KB Output is correct
10 Correct 3 ms 1004 KB Output is correct
11 Correct 3 ms 1004 KB Output is correct
12 Correct 3 ms 1004 KB Output is correct
13 Correct 3 ms 1128 KB Output is correct
14 Correct 3 ms 1168 KB Output is correct
15 Correct 3 ms 1184 KB Output is correct
16 Correct 3 ms 1332 KB Output is correct
17 Correct 4 ms 1332 KB Output is correct
18 Correct 3 ms 1332 KB Output is correct
19 Correct 5 ms 1332 KB Output is correct
20 Correct 3 ms 1332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 468 KB Output is correct
2 Correct 4 ms 616 KB Output is correct
3 Correct 4 ms 760 KB Output is correct
4 Correct 3 ms 868 KB Output is correct
5 Correct 3 ms 868 KB Output is correct
6 Correct 3 ms 928 KB Output is correct
7 Correct 3 ms 964 KB Output is correct
8 Correct 3 ms 984 KB Output is correct
9 Correct 3 ms 1004 KB Output is correct
10 Correct 3 ms 1004 KB Output is correct
11 Correct 3 ms 1004 KB Output is correct
12 Correct 3 ms 1004 KB Output is correct
13 Correct 3 ms 1128 KB Output is correct
14 Correct 3 ms 1168 KB Output is correct
15 Correct 3 ms 1184 KB Output is correct
16 Correct 3 ms 1332 KB Output is correct
17 Correct 4 ms 1332 KB Output is correct
18 Correct 3 ms 1332 KB Output is correct
19 Correct 5 ms 1332 KB Output is correct
20 Correct 3 ms 1332 KB Output is correct
21 Correct 449 ms 13256 KB Output is correct
22 Correct 445 ms 15212 KB Output is correct
23 Correct 418 ms 17304 KB Output is correct
24 Correct 235 ms 18852 KB Output is correct
25 Correct 184 ms 20688 KB Output is correct
26 Correct 194 ms 22412 KB Output is correct
27 Correct 164 ms 24464 KB Output is correct
28 Correct 175 ms 26384 KB Output is correct
29 Correct 162 ms 28496 KB Output is correct
30 Correct 176 ms 30304 KB Output is correct
31 Correct 180 ms 32400 KB Output is correct
32 Correct 193 ms 34256 KB Output is correct
33 Correct 270 ms 35972 KB Output is correct
34 Correct 307 ms 37820 KB Output is correct
35 Correct 298 ms 39420 KB Output is correct
36 Correct 432 ms 41344 KB Output is correct
37 Correct 444 ms 43364 KB Output is correct
38 Correct 455 ms 45476 KB Output is correct
39 Correct 157 ms 47140 KB Output is correct
40 Correct 182 ms 48952 KB Output is correct
41 Correct 183 ms 50664 KB Output is correct
42 Correct 176 ms 52616 KB Output is correct
43 Correct 163 ms 54592 KB Output is correct
44 Correct 168 ms 56548 KB Output is correct
45 Correct 187 ms 58508 KB Output is correct
46 Correct 234 ms 60584 KB Output is correct
47 Correct 185 ms 62544 KB Output is correct
48 Correct 241 ms 64132 KB Output is correct
49 Correct 296 ms 65980 KB Output is correct
50 Correct 249 ms 67748 KB Output is correct