# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
276557 | 2020-08-20T13:47:52 Z | sjimed | Circus (Balkan15_CIRCUS) | C++14 | 1025 ms | 24076 KB |
#include "circus.h" #include<bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(false); cin.tie(0); #define fi first #define se second #define em emplace #define eb emplace_back #define all(v) (v).begin(), (v).end() #define mp make_pair typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<int,pii> piii; const int inf = 1e9; const ll INF = 1e18; int n, m; int dp[100010]; bool chk[100010]; set<int> s; vector<int> p, v1, v2; priority_queue<piii, vector<piii>, greater<piii>> pQ; vector<int> ans; void init(int N, int M, int P[]){ n = N; m = M; for(int i=0; i<n; i++) p.eb(P[i]); p.eb(m); s.insert(m); sort(all(p)); p.erase(unique(all(p)), p.end()); for(int i=0; i<p.size(); i++) s.insert(i); s.insert(-1); s.insert(p.size()); pQ.em(0, mp(p.size()-1, p.size()-1)); while(pQ.size()) { int cost = pQ.top().fi; int x = pQ.top().se.fi; int par = pQ.top().se.se; pQ.pop(); if(x > par) { auto y = *s.upper_bound(x); if(y < p.size()) pQ.em(p[y] - p[par], mp(y, par)); } else { auto y = *prev(s.lower_bound(x)); if(y >= 0) pQ.em(p[par] - p[y], mp(y, par)); } if(chk[x]) continue; chk[x] = true; dp[x] = cost; s.erase(x); int k = lower_bound(all(p), p[x] + cost) - p.begin(); if(k < p.size()) pQ.em(p[k] - p[x], mp(k, x)); k = upper_bound(all(p), p[x] - cost) - p.begin() - 1; if(k >= 0) pQ.em(p[x] - p[k], mp(k, x)); } for(int i=0; i<p.size(); i++) { if(v1.empty() || v1.back() < p[i] - dp[i]) v1.eb(p[i] - dp[i]); else v1.eb(v1.back()); } for(int i=p.size()-1; i>=0; i--) { if(v2.empty() || v2.back() > p[i] + dp[i]) v2.eb(p[i] + dp[i]); else v2.eb(v2.back()); } reverse(all(v2)); } int minLength(int D) { int ret = m - D; int k = lower_bound(all(v1), D) - v1.begin(); ret = min(ret, p[k] - D); k = upper_bound(all(v2), D) - v2.begin() - 1; if(k >= 0) ret = min(ret, D - p[k]); return ret; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 284 ms | 7788 KB | Output is correct |
2 | Correct | 279 ms | 8812 KB | Output is correct |
3 | Correct | 298 ms | 8684 KB | Output is correct |
4 | Correct | 285 ms | 8556 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 512 KB | Output is correct |
6 | Correct | 4 ms | 512 KB | Output is correct |
7 | Correct | 4 ms | 512 KB | Output is correct |
8 | Correct | 4 ms | 512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
3 | Correct | 1 ms | 384 KB | Output is correct |
4 | Correct | 1 ms | 384 KB | Output is correct |
5 | Correct | 5 ms | 512 KB | Output is correct |
6 | Correct | 4 ms | 512 KB | Output is correct |
7 | Correct | 4 ms | 512 KB | Output is correct |
8 | Correct | 4 ms | 512 KB | Output is correct |
9 | Correct | 464 ms | 8440 KB | Output is correct |
10 | Correct | 438 ms | 5112 KB | Output is correct |
11 | Correct | 415 ms | 4472 KB | Output is correct |
12 | Correct | 469 ms | 9196 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 284 ms | 7788 KB | Output is correct |
2 | Correct | 279 ms | 8812 KB | Output is correct |
3 | Correct | 298 ms | 8684 KB | Output is correct |
4 | Correct | 285 ms | 8556 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 512 KB | Output is correct |
10 | Correct | 4 ms | 512 KB | Output is correct |
11 | Correct | 4 ms | 512 KB | Output is correct |
12 | Correct | 4 ms | 512 KB | Output is correct |
13 | Correct | 285 ms | 8000 KB | Output is correct |
14 | Correct | 303 ms | 8900 KB | Output is correct |
15 | Correct | 270 ms | 7664 KB | Output is correct |
16 | Correct | 272 ms | 8624 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 284 ms | 7788 KB | Output is correct |
2 | Correct | 279 ms | 8812 KB | Output is correct |
3 | Correct | 298 ms | 8684 KB | Output is correct |
4 | Correct | 285 ms | 8556 KB | Output is correct |
5 | Correct | 1 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 1 ms | 384 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 5 ms | 512 KB | Output is correct |
10 | Correct | 4 ms | 512 KB | Output is correct |
11 | Correct | 4 ms | 512 KB | Output is correct |
12 | Correct | 4 ms | 512 KB | Output is correct |
13 | Correct | 464 ms | 8440 KB | Output is correct |
14 | Correct | 438 ms | 5112 KB | Output is correct |
15 | Correct | 415 ms | 4472 KB | Output is correct |
16 | Correct | 469 ms | 9196 KB | Output is correct |
17 | Correct | 285 ms | 8000 KB | Output is correct |
18 | Correct | 303 ms | 8900 KB | Output is correct |
19 | Correct | 270 ms | 7664 KB | Output is correct |
20 | Correct | 272 ms | 8624 KB | Output is correct |
21 | Correct | 907 ms | 19436 KB | Output is correct |
22 | Correct | 977 ms | 20976 KB | Output is correct |
23 | Correct | 944 ms | 22776 KB | Output is correct |
24 | Correct | 1025 ms | 24076 KB | Output is correct |