# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
73214 |
2018-08-28T04:53:25 Z |
ainta(#2272) |
Circus (Balkan15_CIRCUS) |
C++11 |
|
2037 ms |
16896 KB |
#include "circus.h"
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<set>
#define SZ 131072
#define pii pair<int,int>
#define INF 1000000010
using namespace std;
int DP[110000][2], DD[110000], MM, X[110000];
bool v[110000];
int IT[SZ + SZ + 2][2];
set<pii>Set;
struct point {
int d, fr;
pii to;
point() {}
point(int d_, int fr_, pii to_) {
d = d_, fr = fr_, to = to_;
}
bool operator<(const point &p)const {
return d>p.d;
}
};
priority_queue<point>PQ;
int n;
void Ins(int fr, pii to) {
int num = to.second, x = to.first;
if (x < fr) {
if (DP[num][0] <= fr - x)return;
DP[num][0] = fr - x;
PQ.push(point(fr - x, fr, to));
}
else {
if (DP[num][1] <= x - fr)return;
DP[num][1] = x - fr;
PQ.push(point(x - fr, fr, to));
}
}
void Do(int x, int d) {
pii tp = pii(x - d, n + 1);
auto it = Set.lower_bound(tp);
if (it != Set.begin()) {
it--;
Ins(x, *it);
}
tp = pii(x + d, -1);
it = Set.lower_bound(tp);
if (it != Set.end()) {
Ins(x, *it);
}
}
void Add(int pv, int a, int b) {
a += SZ;
IT[a][pv] = b;
while (a != 1) {
a >>= 1;
IT[a][pv] = min(IT[a * 2][pv], IT[a * 2 + 1][pv]);
}
}
void init(int N, int M, int P[])
{
n = N;
MM = M;
if (n == 0)return;
int i;
for (i = 0; i<N; i++)DP[i][0] = DP[i][1] = INF;
sort(P, P + N);
for (i = 0; i<n; i++) {
Set.insert(pii(P[i], i));
X[i] = P[i];
}
Ins(M, pii(P[n - 1], n - 1));
point tp;
while (!PQ.empty()) {
tp = PQ.top();
PQ.pop();
int num = tp.to.second, x = tp.to.first;
if (x < tp.fr) {
if (tp.d != DP[num][0])continue;
if (!v[num]) {
v[num] = true;
Do(x, tp.d);
}
if (num != 0) {
Ins(tp.fr, pii(P[num - 1], num - 1));
}
}
else {
if (tp.d != DP[num][1])continue;
if (!v[num]) {
v[num] = true;
Do(x, tp.d);
}
if (num != n - 1) {
Ins(tp.fr, pii(P[num + 1], num + 1));
}
}
}
for (i = 0; i<n; i++)DD[i] = min(DP[i][0], DP[i][1]);
for (i = 0; i<n; i++) {
Add(0, i, DD[i] + X[i]);
Add(1, i, DD[i] - X[i]);
}
}
int Get1(int b, int e, int D) {
if (b>e)return INF;
b += SZ, e += SZ;
while (b <= e) {
if (IT[e][0] <= D)break;
b = b >> 1;
e = (e - 1) >> 1;
}
if (b>e)return INF;
while (e < SZ) {
e = e * 2;
if (IT[e + 1][0] <= D)e++;
}
return D - X[e - SZ];
}
int Get2(int b, int e, int D) {
if (b>e)return INF;
b += SZ, e += SZ;
while (b <= e) {
if (IT[b][1] <= D)break;
b = (b + 1) >> 1;
e = e >> 1;
}
if (b>e)return INF;
while (b < SZ) {
b = b * 2;
if (IT[b][1] > D)b++;
}
return X[b - SZ] + D;
}
int minLength(int D)
{
if (!n)return MM - D;
auto tp = Set.lower_bound(pii(D, -1));
int mm, i;
if (tp == Set.end())mm = n;
else mm = tp->second;
int t1 = Get1(0, mm - 1, D), t2 = Get2(mm, n - 1, -D);
return min(min(t1, t2), MM - D);
}
Compilation message
circus.cpp: In function 'int minLength(int)':
circus.cpp:146:10: warning: unused variable 'i' [-Wunused-variable]
int mm, i;
^
grader.cpp: In function 'int main()':
grader.cpp:14:12: warning: unused variable 'max_code' [-Wunused-variable]
long long max_code;
^~~~~~~~
grader.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &M);
~~~~~^~~~~~~~~~~~~~~~
grader.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &P[i]);
~~~~~^~~~~~~~~~~~~
grader.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &Q);
~~~~~^~~~~~~~~~
grader.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &d);
~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
185 ms |
8824 KB |
Output is correct |
2 |
Correct |
167 ms |
8848 KB |
Output is correct |
3 |
Correct |
143 ms |
8848 KB |
Output is correct |
4 |
Correct |
171 ms |
8872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8872 KB |
Output is correct |
2 |
Correct |
2 ms |
8872 KB |
Output is correct |
3 |
Correct |
2 ms |
8872 KB |
Output is correct |
4 |
Correct |
2 ms |
8872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8872 KB |
Output is correct |
2 |
Correct |
2 ms |
8872 KB |
Output is correct |
3 |
Correct |
2 ms |
8872 KB |
Output is correct |
4 |
Correct |
2 ms |
8872 KB |
Output is correct |
5 |
Correct |
5 ms |
8872 KB |
Output is correct |
6 |
Correct |
5 ms |
8872 KB |
Output is correct |
7 |
Correct |
5 ms |
8872 KB |
Output is correct |
8 |
Correct |
5 ms |
8872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8872 KB |
Output is correct |
2 |
Correct |
2 ms |
8872 KB |
Output is correct |
3 |
Correct |
2 ms |
8872 KB |
Output is correct |
4 |
Correct |
2 ms |
8872 KB |
Output is correct |
5 |
Correct |
5 ms |
8872 KB |
Output is correct |
6 |
Correct |
5 ms |
8872 KB |
Output is correct |
7 |
Correct |
5 ms |
8872 KB |
Output is correct |
8 |
Correct |
5 ms |
8872 KB |
Output is correct |
9 |
Correct |
614 ms |
8892 KB |
Output is correct |
10 |
Correct |
526 ms |
8892 KB |
Output is correct |
11 |
Correct |
485 ms |
8892 KB |
Output is correct |
12 |
Correct |
642 ms |
9328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
185 ms |
8824 KB |
Output is correct |
2 |
Correct |
167 ms |
8848 KB |
Output is correct |
3 |
Correct |
143 ms |
8848 KB |
Output is correct |
4 |
Correct |
171 ms |
8872 KB |
Output is correct |
5 |
Correct |
3 ms |
8872 KB |
Output is correct |
6 |
Correct |
2 ms |
8872 KB |
Output is correct |
7 |
Correct |
2 ms |
8872 KB |
Output is correct |
8 |
Correct |
2 ms |
8872 KB |
Output is correct |
9 |
Correct |
5 ms |
8872 KB |
Output is correct |
10 |
Correct |
5 ms |
8872 KB |
Output is correct |
11 |
Correct |
5 ms |
8872 KB |
Output is correct |
12 |
Correct |
5 ms |
8872 KB |
Output is correct |
13 |
Correct |
153 ms |
9328 KB |
Output is correct |
14 |
Correct |
146 ms |
9328 KB |
Output is correct |
15 |
Correct |
153 ms |
9328 KB |
Output is correct |
16 |
Correct |
147 ms |
9328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
185 ms |
8824 KB |
Output is correct |
2 |
Correct |
167 ms |
8848 KB |
Output is correct |
3 |
Correct |
143 ms |
8848 KB |
Output is correct |
4 |
Correct |
171 ms |
8872 KB |
Output is correct |
5 |
Correct |
3 ms |
8872 KB |
Output is correct |
6 |
Correct |
2 ms |
8872 KB |
Output is correct |
7 |
Correct |
2 ms |
8872 KB |
Output is correct |
8 |
Correct |
2 ms |
8872 KB |
Output is correct |
9 |
Correct |
5 ms |
8872 KB |
Output is correct |
10 |
Correct |
5 ms |
8872 KB |
Output is correct |
11 |
Correct |
5 ms |
8872 KB |
Output is correct |
12 |
Correct |
5 ms |
8872 KB |
Output is correct |
13 |
Correct |
614 ms |
8892 KB |
Output is correct |
14 |
Correct |
526 ms |
8892 KB |
Output is correct |
15 |
Correct |
485 ms |
8892 KB |
Output is correct |
16 |
Correct |
642 ms |
9328 KB |
Output is correct |
17 |
Correct |
153 ms |
9328 KB |
Output is correct |
18 |
Correct |
146 ms |
9328 KB |
Output is correct |
19 |
Correct |
153 ms |
9328 KB |
Output is correct |
20 |
Correct |
147 ms |
9328 KB |
Output is correct |
21 |
Correct |
1617 ms |
14024 KB |
Output is correct |
22 |
Correct |
1792 ms |
14024 KB |
Output is correct |
23 |
Correct |
1743 ms |
15640 KB |
Output is correct |
24 |
Correct |
2037 ms |
16896 KB |
Output is correct |