답안 #91562

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

using namespace std;

const int Nmax = 1e5 + 5, lim = 1e9;
const long double eps = 0;


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


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

    Node() {}

    Node(Node *_prv, Node *_nxt, int _val, long double _dprev, long double _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)
{
    Node *k = create_list();
    --k->val;

    int i;
    long double rest;

    for(i=1; i<n; ++i)
    {
        if(k->val > 0)
        {
            rest = 2.0 * S * T;
        }
        else if(k->prv && k->dprev - eps <= 2.0 * S * T)
        {
            rest = 2.0 * S * T - k->dprev;
            if(rest < 0) rest = 0;

            unite_front(k);
        }
        else if(k->nxt && k->dnext - eps <= 2.0 * S * T)
        {
            rest = 2.0 * S * T - k->dnext;
            if(rest < 0) rest = 0;

            unite_back(k);
        }
        else return 0;
        --k->val;

        long double R = rest;
        while(1)
        {
            if(k->prv && k->dprev <= R)
            {
                R -= k->dprev;
                unite_front(k);
                continue;
            }

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

            if(k->prv && (!k->nxt || k->dprev < k->dnext))
            {
                k->dprev -= R;
                k->prv->dnext -= R;
            }
            else if(k->nxt)
            {
                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 = 1e9, 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 376 KB Output is correct
2 Correct 2 ms 444 KB Output is correct
3 Correct 2 ms 444 KB Output is correct
4 Correct 2 ms 444 KB Output is correct
5 Correct 2 ms 444 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Incorrect 2 ms 512 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 444 KB Output is correct
3 Correct 2 ms 444 KB Output is correct
4 Correct 2 ms 444 KB Output is correct
5 Correct 2 ms 444 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Incorrect 2 ms 512 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 444 KB Output is correct
3 Correct 2 ms 444 KB Output is correct
4 Correct 2 ms 444 KB Output is correct
5 Correct 2 ms 444 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Incorrect 2 ms 512 KB Output isn't correct
8 Halted 0 ms 0 KB -