Submission #58145

# Submission time Handle Problem Language Result Execution time Memory
58145 2018-07-17T04:10:43 Z King Suryal(#1687) Candies (JOI18_candies) C++11
0 / 100
3 ms 376 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;
} 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->x == -1);
        ans += x->x;
        printf("%lld\n", ans);
        if (x->l && x->r) {
            x->x = x->l->x + x->r->x - x->x;
            x->l->x = -1;
            x->r->x = -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->r = 0;
            if (x->r) x->r->l = 0;
        }
    }
	return 0;
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
candies.cpp:37: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 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -