# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
40785 |
2018-02-08T07:13:46 Z |
ssnsarang2023 |
Gap (APIO16_gap) |
C++14 |
|
79 ms |
2284 KB |
#include <bits/stdc++.h>
#include "gap.h"
using namespace std;
typedef long long ll;
//#define DEBUG
#ifdef DEBUG
int n = 5;
ll a[5] = {2, 3, 6, 8, 12};
void MinMax(ll x, ll y, ll *mn, ll *mx) {
for (int i = 0; i < n; ++i) if (a[i] >= x)
{ (*mn) = a[i]; break; }
for (int i = n - 1; i >= 0; --i) if (a[i] <= y)
{ (*mx) = a[i]; break; }
if ((*mx) < (*mn)) (*mx) = (*mn) = -1;
}
#endif
ll findGap(int _t, int _n) {
ll n = _n;
ll mn = 1, mx = (ll)1e18;
MinMax(mn, mx, &mn, &mx);
if (_t == 2) {
ll d = (mx - mn) / n, mod = (mx - mn) % n, pre = mn;
ll pstep = mn, step = mn + d - 1 + (mod != 0ll), gap = 0;
if (mod) --mod;
while (1) {
ll mntmp = -1, mxtmp = -1;
if (pstep <= min(mx - 1, step)) MinMax(pstep + 1, min(mx - 1, step), &mntmp, &mxtmp);
if (step >= mx) {
if (mxtmp != -1) gap = max(gap, mx - mxtmp);
else gap = max(gap, mx - pre);
break;
} else if (mntmp != -1) gap = max(gap, mntmp - pre);
pre = max(pre, mxtmp), pstep = step, step += d + (mod != 0);
if (mod) --mod;
}
return gap;
} else {
vector<ll> a;
a.resize(n);
a[0] = mn, a[n - 1] = mx;
int lo = 0, hi = n - 1;
while (hi - lo > 1) {
MinMax(a[lo] + 1ll, a[hi] - 1ll, &mn, &mx);
++lo, --hi;
a[lo] = mn, a[hi] = mx;
}
ll gap = 0;
for (int i = 0; i < n - 1; ++i) gap = max(gap, a[i + 1] - a[i]);
return gap;
}
return 0ll;
}
#ifdef DEBUG
int main() {
printf("%d", findGap(1, 5));
return 0;
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
352 KB |
Output is correct |
3 |
Correct |
2 ms |
424 KB |
Output is correct |
4 |
Correct |
2 ms |
440 KB |
Output is correct |
5 |
Correct |
2 ms |
440 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
496 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
548 KB |
Output is correct |
11 |
Correct |
2 ms |
548 KB |
Output is correct |
12 |
Correct |
2 ms |
600 KB |
Output is correct |
13 |
Correct |
2 ms |
620 KB |
Output is correct |
14 |
Correct |
2 ms |
620 KB |
Output is correct |
15 |
Correct |
2 ms |
620 KB |
Output is correct |
16 |
Correct |
17 ms |
1004 KB |
Output is correct |
17 |
Correct |
14 ms |
1004 KB |
Output is correct |
18 |
Correct |
16 ms |
1004 KB |
Output is correct |
19 |
Correct |
15 ms |
1004 KB |
Output is correct |
20 |
Correct |
12 ms |
1004 KB |
Output is correct |
21 |
Correct |
57 ms |
2156 KB |
Output is correct |
22 |
Correct |
54 ms |
2156 KB |
Output is correct |
23 |
Correct |
53 ms |
2156 KB |
Output is correct |
24 |
Correct |
65 ms |
2156 KB |
Output is correct |
25 |
Correct |
48 ms |
2156 KB |
Output is correct |
26 |
Correct |
56 ms |
2156 KB |
Output is correct |
27 |
Correct |
54 ms |
2156 KB |
Output is correct |
28 |
Correct |
55 ms |
2156 KB |
Output is correct |
29 |
Correct |
55 ms |
2284 KB |
Output is correct |
30 |
Correct |
40 ms |
2284 KB |
Output is correct |
31 |
Correct |
2 ms |
2284 KB |
Output is correct |
32 |
Correct |
2 ms |
2284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
2284 KB |
Execution failed because the return code was nonzero |
2 |
Runtime error |
1 ms |
2284 KB |
Execution failed because the return code was nonzero |
3 |
Runtime error |
1 ms |
2284 KB |
Execution failed because the return code was nonzero |
4 |
Runtime error |
1 ms |
2284 KB |
Execution failed because the return code was nonzero |
5 |
Runtime error |
1 ms |
2284 KB |
Execution failed because the return code was nonzero |
6 |
Runtime error |
2 ms |
2284 KB |
Execution failed because the return code was nonzero |
7 |
Runtime error |
2 ms |
2284 KB |
Execution failed because the return code was nonzero |
8 |
Runtime error |
1 ms |
2284 KB |
Execution failed because the return code was nonzero |
9 |
Runtime error |
2 ms |
2284 KB |
Execution failed because the return code was nonzero |
10 |
Runtime error |
1 ms |
2284 KB |
Execution failed because the return code was nonzero |
11 |
Runtime error |
2 ms |
2284 KB |
Execution failed because the return code was nonzero |
12 |
Runtime error |
3 ms |
2284 KB |
Execution failed because the return code was nonzero |
13 |
Runtime error |
3 ms |
2284 KB |
Execution failed because the return code was nonzero |
14 |
Runtime error |
2 ms |
2284 KB |
Execution failed because the return code was nonzero |
15 |
Runtime error |
2 ms |
2284 KB |
Execution failed because the return code was nonzero |
16 |
Runtime error |
19 ms |
2284 KB |
Execution failed because the return code was nonzero |
17 |
Runtime error |
19 ms |
2284 KB |
Execution failed because the return code was nonzero |
18 |
Runtime error |
19 ms |
2284 KB |
Execution failed because the return code was nonzero |
19 |
Runtime error |
20 ms |
2284 KB |
Execution failed because the return code was nonzero |
20 |
Runtime error |
11 ms |
2284 KB |
Execution failed because the return code was nonzero |
21 |
Runtime error |
77 ms |
2284 KB |
Execution failed because the return code was nonzero |
22 |
Runtime error |
79 ms |
2284 KB |
Execution failed because the return code was nonzero |
23 |
Runtime error |
72 ms |
2284 KB |
Execution failed because the return code was nonzero |
24 |
Runtime error |
72 ms |
2284 KB |
Execution failed because the return code was nonzero |
25 |
Runtime error |
70 ms |
2284 KB |
Execution failed because the return code was nonzero |
26 |
Runtime error |
74 ms |
2284 KB |
Execution failed because the return code was nonzero |
27 |
Runtime error |
75 ms |
2284 KB |
Execution failed because the return code was nonzero |
28 |
Runtime error |
77 ms |
2284 KB |
Execution failed because the return code was nonzero |
29 |
Runtime error |
76 ms |
2284 KB |
Execution failed because the return code was nonzero |
30 |
Runtime error |
43 ms |
2284 KB |
Execution failed because the return code was nonzero |
31 |
Runtime error |
2 ms |
2284 KB |
Execution failed because the return code was nonzero |
32 |
Runtime error |
2 ms |
2284 KB |
Execution failed because the return code was nonzero |