# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
523818 |
2022-02-08T08:35:49 Z |
valerikk |
Gap (APIO16_gap) |
C++17 |
|
66 ms |
4184 KB |
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = (ll)1e18;
ll MN, MX;
pair<ll, ll> get(ll l, ll r) {
MinMax(l, r, &MN, &MX);
return {MN, MX};
}
ll findGap(int t, int n) {
if (t == 1) {
vector<ll> lft, rght;
ll l = 0, r = INF;
for (int i = 0; i < (n + 1) / 2; ++i) {
auto [L, R] = get(l, r);
lft.push_back(L);
if (L != R) rght.push_back(R);
l = L + 1;
r = R - 1;
}
while (!rght.empty()) {
lft.push_back(rght.back());
rght.pop_back();
}
ll res = 0;
for (int i = 1; i < (int)lft.size(); ++i) {
//assert(lft[i - 1] < lft[i]);
res = max(res, lft[i] - lft[i - 1]);
}
return res;
}
if (t == 2) {
auto [l, r] = get(0, INF);
ll d = (r - l + n - 2) / (n - 1);
ll res = d;
vector<pair<ll, ll>> segs;
ll cur = l;
while (cur <= r) {
segs.push_back({cur, min(r, cur + d)});
cur = cur + d + 1;
}
vector<ll> mx(segs.size()), mn(segs.size());
for (int i = 0; i < (int)segs.size(); ++i) {
auto [L, R] = get(segs[i].first, segs[i].second);
mx[i] = R;
mn[i] = L == -1 ? INF + 1 : L;
}
for (int i = 1; i < (int)segs.size(); ++i) {
mx[i] = max(mx[i], mx[i - 1]);
}
for (int i = (int)segs.size() - 2; i >= 0; --i) {
mn[i] = min(mn[i], mn[i + 1]);
}
for (int i = 1; i < (int)segs.size(); ++i) {
if (mx[i - 1] != -1 && mn[i] != INF + 1) {
res = max(res, mn[i] - mx[i - 1]);
}
}
return res;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
0 ms |
200 KB |
Output is correct |
5 |
Correct |
0 ms |
200 KB |
Output is correct |
6 |
Correct |
0 ms |
200 KB |
Output is correct |
7 |
Correct |
0 ms |
200 KB |
Output is correct |
8 |
Correct |
0 ms |
200 KB |
Output is correct |
9 |
Correct |
0 ms |
200 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
9 ms |
968 KB |
Output is correct |
17 |
Correct |
9 ms |
948 KB |
Output is correct |
18 |
Correct |
9 ms |
976 KB |
Output is correct |
19 |
Correct |
12 ms |
960 KB |
Output is correct |
20 |
Correct |
9 ms |
968 KB |
Output is correct |
21 |
Correct |
40 ms |
2616 KB |
Output is correct |
22 |
Correct |
43 ms |
2524 KB |
Output is correct |
23 |
Correct |
37 ms |
2664 KB |
Output is correct |
24 |
Correct |
35 ms |
2576 KB |
Output is correct |
25 |
Correct |
40 ms |
2616 KB |
Output is correct |
26 |
Correct |
44 ms |
2592 KB |
Output is correct |
27 |
Correct |
37 ms |
2532 KB |
Output is correct |
28 |
Correct |
37 ms |
2624 KB |
Output is correct |
29 |
Correct |
45 ms |
2552 KB |
Output is correct |
30 |
Correct |
34 ms |
2560 KB |
Output is correct |
31 |
Correct |
0 ms |
200 KB |
Output is correct |
32 |
Correct |
0 ms |
200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
0 ms |
200 KB |
Output is correct |
5 |
Correct |
1 ms |
200 KB |
Output is correct |
6 |
Correct |
0 ms |
200 KB |
Output is correct |
7 |
Correct |
1 ms |
200 KB |
Output is correct |
8 |
Correct |
1 ms |
200 KB |
Output is correct |
9 |
Correct |
0 ms |
200 KB |
Output is correct |
10 |
Correct |
1 ms |
200 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
12 ms |
1252 KB |
Output is correct |
17 |
Correct |
13 ms |
1216 KB |
Output is correct |
18 |
Correct |
13 ms |
1216 KB |
Output is correct |
19 |
Correct |
13 ms |
1292 KB |
Output is correct |
20 |
Correct |
8 ms |
1216 KB |
Output is correct |
21 |
Correct |
59 ms |
4176 KB |
Output is correct |
22 |
Correct |
56 ms |
4184 KB |
Output is correct |
23 |
Correct |
51 ms |
4144 KB |
Output is correct |
24 |
Correct |
52 ms |
4112 KB |
Output is correct |
25 |
Correct |
55 ms |
4152 KB |
Output is correct |
26 |
Correct |
66 ms |
4112 KB |
Output is correct |
27 |
Correct |
53 ms |
4108 KB |
Output is correct |
28 |
Correct |
53 ms |
4156 KB |
Output is correct |
29 |
Correct |
55 ms |
4184 KB |
Output is correct |
30 |
Correct |
28 ms |
3760 KB |
Output is correct |
31 |
Correct |
0 ms |
200 KB |
Output is correct |
32 |
Correct |
0 ms |
200 KB |
Output is correct |