# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
631541 |
2022-08-18T08:20:06 Z |
TranGiaHuy1508 |
Gap (APIO16_gap) |
C++17 |
|
61 ms |
2648 KB |
#include <bits/stdc++.h>
using namespace std;
#include "gap.h"
using ll = long long;
ll findGap(int T, int N){
if (T == 1){
ll mn, mx;
vector<ll> L, R;
ll lb = -1, rb = (ll)1e18 + 1;
while (N > 0 && lb + 1 <= rb - 1){
MinMax(lb + 1, rb - 1, &mn, &mx);
if (mn < 0) break;
L.push_back(mn); R.push_back(mx);
N--; if (mn != mx) N--;
lb = mn; rb = mx;
}
ll res = 0;
for (int i = 1; i < (int)L.size(); i++){
res = max(res, abs(L[i] - L[i-1]));
}
for (int i = 1; i < (int)R.size(); i++){
res = max(res, abs(R[i] - R[i-1]));
}
res = max(res, abs(R.back() - L.back()));
return res;
}
else{
ll mn, mx;
MinMax(0, (ll)1e18, &mn, &mx);
ll d = mx - mn;
ll st = mn + 1;
vector<pair<ll, ll>> v(N);
for (int i = 0; i < N; i++){
ll dist = d/N + (i < d%N);
v[i] = {st, st + dist - 1};
st += dist;
}
ll res = 0, lst = mn;
for (int i = 0; i < N; i++){
if (v[i].first <= v[i].second){
ll a, b;
MinMax(v[i].first, v[i].second, &a, &b);
if (a < 0) continue;
res = max(res, a - lst);
res = max(res, b - a);
lst = b;
}
}
return res;
}
}
# |
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 |
1 ms |
356 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
12 ms |
820 KB |
Output is correct |
17 |
Correct |
11 ms |
820 KB |
Output is correct |
18 |
Correct |
9 ms |
792 KB |
Output is correct |
19 |
Correct |
9 ms |
804 KB |
Output is correct |
20 |
Correct |
7 ms |
816 KB |
Output is correct |
21 |
Correct |
39 ms |
1992 KB |
Output is correct |
22 |
Correct |
35 ms |
2000 KB |
Output is correct |
23 |
Correct |
44 ms |
2012 KB |
Output is correct |
24 |
Correct |
44 ms |
2088 KB |
Output is correct |
25 |
Correct |
35 ms |
2008 KB |
Output is correct |
26 |
Correct |
36 ms |
1908 KB |
Output is correct |
27 |
Correct |
36 ms |
2000 KB |
Output is correct |
28 |
Correct |
40 ms |
2004 KB |
Output is correct |
29 |
Correct |
37 ms |
1928 KB |
Output is correct |
30 |
Correct |
27 ms |
1972 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 |
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 |
2 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 |
12 ms |
808 KB |
Output is correct |
17 |
Correct |
13 ms |
848 KB |
Output is correct |
18 |
Correct |
12 ms |
848 KB |
Output is correct |
19 |
Correct |
12 ms |
848 KB |
Output is correct |
20 |
Correct |
8 ms |
848 KB |
Output is correct |
21 |
Correct |
53 ms |
2592 KB |
Output is correct |
22 |
Correct |
53 ms |
2616 KB |
Output is correct |
23 |
Correct |
52 ms |
2648 KB |
Output is correct |
24 |
Correct |
60 ms |
2636 KB |
Output is correct |
25 |
Correct |
46 ms |
2596 KB |
Output is correct |
26 |
Correct |
50 ms |
2588 KB |
Output is correct |
27 |
Correct |
52 ms |
2632 KB |
Output is correct |
28 |
Correct |
52 ms |
2592 KB |
Output is correct |
29 |
Correct |
61 ms |
2596 KB |
Output is correct |
30 |
Correct |
26 ms |
2648 KB |
Output is correct |
31 |
Correct |
1 ms |
208 KB |
Output is correct |
32 |
Correct |
0 ms |
208 KB |
Output is correct |