답안 #91569

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91569 2018-12-28T12:21:29 Z Alexa2001 Sparklers (JOI17_sparklers) C++17
0 / 100
2 ms 740 KB
#include <bits/stdc++.h>

using namespace std;

const int Nmax = 1e5 + 5, lim = 1e9;

int X[Nmax];
int n, K, T;


struct Node
{
    Node *prv, *nxt;
    int val;
    int dprev, dnext;

    Node() {}

    Node(Node *_prv, Node *_nxt, int _val, int _dprev, int _dnext)
    {
        prv = _prv, nxt = _nxt; val = _val; dprev = _dprev; dnext = _dnext;
    }
};

Node *create_list()
{
    int i;
    Node *act = new Node(NULL, NULL, 1, -1, -1), *now, *special;
    special = act;

    for(i=2; i<=n; ++i)
    {
        if(X[i] == X[i-1])
            ++act -> val;
        else
        {
            now = new Node(act, NULL, 1, X[i] - X[i-1], -1);
            act -> dnext = X[i] - X[i-1];
            act -> nxt = now;
            act = now;
        }

        if(i == K) special = act;
    }
    return special;
}

void unite_front(Node *k)
{
    Node *u = k->prv;
    k->dprev = u->dprev;
    k->prv = u->prv;
    k->val += u->val;

    if(k->prv)
    {
        k->prv->nxt = k;
        k->prv->dnext = k->dprev;
    }
}

void unite_back(Node *k)
{
    Node *u = k->nxt;
    k->dnext = u->dnext;
    k->nxt = u->nxt;
    k->val += u->val;

    if(k->nxt)
    {
        k->nxt->prv = k;
        k->nxt->dprev = k->dnext;
    }
}

bool check(int S)
{
    if(2LL * S * T >= 1LL * lim) return 1;

    Node *k = create_list();
    --k->val;

    int i;
    int rest;

    for(i=1; i<n; ++i)
    {
        if(k->val > 0)
        {
            rest = 2 * S * T;
        }
        else if(k->prv && k->dprev <= 2 * S * T && (!k->nxt || k->dprev < k->dnext))
        {
            rest = 2 * S * T - k->dprev;
            unite_front(k);
        }
        else if(k->nxt && k->dnext <= 2 * S * T)
        {
            rest = 2 * S * T - k->dnext;
            unite_back(k);
        }
        else return 0;
        --k->val;

        int R = rest;
        while(1)
        {
            if(k->prv && (!k->nxt || k->dprev < k->dnext))
            {
                if(k->dprev <= R)
                {
                    R -= k->dprev;
                    unite_front(k);
                    continue;
                }

                k->dprev -= R;
                k->prv->dnext -= R;
            }
            else if(k->nxt)
            {
                if(k->dnext <= R)
                {
                    R -= k->dnext;
                    unite_back(k);
                    continue;
                }

                k->dnext -= R;
                k->nxt->dprev -= R;
            }

            break;
        }
    }
    return 1;
}

int main()
{
  //  freopen("input", "r", stdin);
    cin.sync_with_stdio(false);

    int i;
    cin >> n >> K >> T;
    for(i=1; i<=n; ++i) cin >> X[i];

    int st = 0, dr = lim, mid;
    while(st <= dr)
    {
        mid = (st + dr) / 2;
        if(check(mid)) dr = mid-1;
            else st = mid+1;
    }
    cout << st << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 464 KB Output is correct
5 Correct 2 ms 524 KB Output is correct
6 Correct 2 ms 740 KB Output is correct
7 Incorrect 2 ms 740 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 464 KB Output is correct
5 Correct 2 ms 524 KB Output is correct
6 Correct 2 ms 740 KB Output is correct
7 Incorrect 2 ms 740 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 464 KB Output is correct
5 Correct 2 ms 524 KB Output is correct
6 Correct 2 ms 740 KB Output is correct
7 Incorrect 2 ms 740 KB Output isn't correct
8 Halted 0 ms 0 KB -