# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
546395 |
2022-04-07T12:45:11 Z |
marsxiang5902 |
Gap (APIO16_gap) |
C++14 |
|
104 ms |
5860 KB |
#ifndef LOCAL_PROJECT
#include "gap.h"
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MN = 2e5+5;
const ll MX = ll(1e9) * ll(1e9);
#ifdef LOCAL_PROJECT
int __T, __N; ll ar[MN], M = 0;
void MinMax(ll s, ll t, ll *mn, ll *mx){
++M;
int a = lower_bound(ar, ar+__N, s) - ar, b = upper_bound(ar, ar+__N, t) - ar - 1;
if(a > b){
*mn = *mx = -1;
return;
}
if(__T == 2)
M += b-a+1;
*mn = ar[a]; *mx = ar[b];
}
#endif
int N;
set<ll> ans;
void add(ll x){ ans.insert(x); }
void add(vector<ll> x){ ans.insert(x.begin(), x.end()); }
ll getAns(){
ans.erase(-1);
ll ret = 0;
for(auto it = ans.begin(), it2 = next(it); it2 != ans.end(); it++, it2++)
ret = max(ret, *it2 - *it);
return ret;
}
ll solve1(){
ll pvMn = -1, pvMx = MX+1;
for(int l = 0, r = N-1; l <= r; l++, r--){
MinMax(pvMn + 1, pvMx - 1, &pvMn, &pvMx);
add({pvMn, pvMx});
} return getAns();
}
ll solve2(){
ll mn, mx;
MinMax(0, MX, &mn, &mx);
ll mnAns = (mx-mn) / (N-1) + 1;
add({mn, mx});
for(ll i = mn+1, a, b; i < mx; i += mnAns){
MinMax(i, min(i + mnAns, mx) - 1, &a, &b);
add({a, b});
}
return getAns();
}
ll findGap(int T, int _N){
N = _N;
return T == 1 || N <= 7 ? solve1() : solve2();
}
#ifdef LOCAL_PROJECT
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> __T >> __N;
for(int i = 0; i < __N; i++)
cin >> ar[i];
sort(ar, ar+__N);
ll res = findGap(__T, __N);
printf("%lld %lld\n", res, M);
ll realAns = 0;
for(int i = 0; i < __N-1; i++)
realAns = max(realAns, ar[i+1] - ar[i]);
assert(res == realAns && (__T == 1 ? M <= (__N+1) / 2 : M <= 3*__N));
return 0;
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
14 ms |
1652 KB |
Output is correct |
17 |
Correct |
15 ms |
1684 KB |
Output is correct |
18 |
Correct |
17 ms |
1636 KB |
Output is correct |
19 |
Correct |
14 ms |
1680 KB |
Output is correct |
20 |
Correct |
11 ms |
1616 KB |
Output is correct |
21 |
Correct |
60 ms |
5668 KB |
Output is correct |
22 |
Correct |
66 ms |
5860 KB |
Output is correct |
23 |
Correct |
67 ms |
5760 KB |
Output is correct |
24 |
Correct |
78 ms |
5668 KB |
Output is correct |
25 |
Correct |
56 ms |
5692 KB |
Output is correct |
26 |
Correct |
57 ms |
5708 KB |
Output is correct |
27 |
Correct |
59 ms |
5792 KB |
Output is correct |
28 |
Correct |
60 ms |
5668 KB |
Output is correct |
29 |
Correct |
65 ms |
5676 KB |
Output is correct |
30 |
Correct |
59 ms |
5668 KB |
Output is correct |
31 |
Correct |
0 ms |
208 KB |
Output is correct |
32 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
2 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
336 KB |
Output is correct |
16 |
Correct |
23 ms |
1620 KB |
Output is correct |
17 |
Correct |
19 ms |
1504 KB |
Output is correct |
18 |
Correct |
19 ms |
1488 KB |
Output is correct |
19 |
Correct |
20 ms |
1480 KB |
Output is correct |
20 |
Correct |
9 ms |
464 KB |
Output is correct |
21 |
Correct |
82 ms |
5160 KB |
Output is correct |
22 |
Correct |
95 ms |
5168 KB |
Output is correct |
23 |
Correct |
87 ms |
5284 KB |
Output is correct |
24 |
Correct |
91 ms |
5232 KB |
Output is correct |
25 |
Correct |
94 ms |
5684 KB |
Output is correct |
26 |
Correct |
104 ms |
5316 KB |
Output is correct |
27 |
Correct |
82 ms |
5280 KB |
Output is correct |
28 |
Correct |
87 ms |
5244 KB |
Output is correct |
29 |
Correct |
85 ms |
5208 KB |
Output is correct |
30 |
Correct |
55 ms |
1876 KB |
Output is correct |
31 |
Correct |
0 ms |
208 KB |
Output is correct |
32 |
Correct |
0 ms |
208 KB |
Output is correct |