Submission #91560

#TimeUsernameProblemLanguageResultExecution timeMemory
91560Alexa2001Sparklers (JOI17_sparklers)C++17
0 / 100
2 ms440 KiB
#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; if(k->prv && k->nxt && k->dprev < k->dnext) { long double R = rest; while(k->prv && k->dprev < R) { R -= k->dprev; unite_front(k); } if(k->prv) { k->dprev -= R; k->prv->dnext -= R; } while(k->nxt && k->dnext < R) { R -= k->dnext; unite_back(k); } if(k->nxt) { k->dnext -= R; k->nxt->dprev -= R; } } else { long double R = rest; while(k->nxt && k->dnext < R) { R -= k->dnext; unite_back(k); } if(k->nxt) { k->dnext -= R; k->nxt->dprev -= R; } while(k->prv && k->dprev < R) { R -= k->dprev; unite_front(k); } if(k->prv) { k->dprev -= R; k->prv->dnext -= R; } } } 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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...