#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
long long findGap(int test, int n) {
ll arr[n];
ll s, t, ans;
if (test == 1) {
ans = 0;
s = 0; t = 1e18;
for (int i=0;i<n/2;i++) {
MinMax(s, t, &arr[i], &arr[n - i - 1]);
s = arr[i] + 1; t = arr[n - i - 1] - 1;
}
if (n % 2 == 1) {
MinMax(s, t, &arr[n/2], &arr[n/2]);
}
for (int i=1;i<n;i++) {
ans = max(ans, arr[i] - arr[i-1]);
}
return ans;
} else {
ans = 0;
s = 0; t = 1e18;
MinMax(s, t, &arr[0], &arr[n-1]);
if (n == 2) {
return arr[1] - arr[0];
}
vector<ll> chunks(n - 2, (arr[n-1] - arr[0] - 1)/(n - 2));
for (ll i=0;i<(t - s - 1)%(n - 2);i++) {
chunks[i] ++;
}
vector<ll> nums = {arr[0]};
ll bruh = arr[0] + 1, mn, mx;
for (int i=0;i<n-2;i++) {
MinMax(bruh, bruh + chunks[i] - 1, &mn, &mx);
if (mn == -1) {
continue;
}
nums.push_back(mn); nums.push_back(mx);
bruh += chunks[i];
}
nums.push_back(arr[n-1]);
for (ll i=1;i<nums.size();i++) {
ans = max(ans, nums[i] - nums[i-1]);
}
return ans;
}
}
Compilation message
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:45:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for (ll i=1;i<nums.size();i++) {
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2392 KB |
Output is correct |
4 |
Correct |
0 ms |
2392 KB |
Output is correct |
5 |
Correct |
0 ms |
2392 KB |
Output is correct |
6 |
Correct |
0 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
0 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
0 ms |
2392 KB |
Output is correct |
11 |
Correct |
0 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
5 ms |
2736 KB |
Output is correct |
17 |
Correct |
8 ms |
2648 KB |
Output is correct |
18 |
Correct |
5 ms |
2648 KB |
Output is correct |
19 |
Correct |
5 ms |
2648 KB |
Output is correct |
20 |
Correct |
4 ms |
2768 KB |
Output is correct |
21 |
Correct |
22 ms |
3584 KB |
Output is correct |
22 |
Correct |
29 ms |
3416 KB |
Output is correct |
23 |
Correct |
22 ms |
3644 KB |
Output is correct |
24 |
Correct |
27 ms |
3648 KB |
Output is correct |
25 |
Correct |
19 ms |
3556 KB |
Output is correct |
26 |
Correct |
21 ms |
3416 KB |
Output is correct |
27 |
Correct |
25 ms |
3444 KB |
Output is correct |
28 |
Correct |
22 ms |
3416 KB |
Output is correct |
29 |
Correct |
21 ms |
3604 KB |
Output is correct |
30 |
Correct |
17 ms |
3416 KB |
Output is correct |
31 |
Correct |
0 ms |
2392 KB |
Output is correct |
32 |
Correct |
0 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2644 KB |
Output is correct |
2 |
Incorrect |
0 ms |
2392 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
5 |
Correct |
0 ms |
2388 KB |
Output is correct |
6 |
Incorrect |
0 ms |
2392 KB |
Output isn't correct |
7 |
Incorrect |
0 ms |
2392 KB |
Output isn't correct |
8 |
Incorrect |
0 ms |
2392 KB |
Output isn't correct |
9 |
Incorrect |
0 ms |
2392 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
11 |
Incorrect |
0 ms |
2392 KB |
Output isn't correct |
12 |
Incorrect |
0 ms |
2392 KB |
Output isn't correct |
13 |
Incorrect |
0 ms |
2392 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Incorrect |
5 ms |
2904 KB |
Output isn't correct |
17 |
Incorrect |
5 ms |
2904 KB |
Output isn't correct |
18 |
Incorrect |
5 ms |
2904 KB |
Output isn't correct |
19 |
Incorrect |
5 ms |
2904 KB |
Output isn't correct |
20 |
Incorrect |
4 ms |
2904 KB |
Output isn't correct |
21 |
Incorrect |
21 ms |
4440 KB |
Output isn't correct |
22 |
Incorrect |
20 ms |
4184 KB |
Output isn't correct |
23 |
Incorrect |
21 ms |
4184 KB |
Output isn't correct |
24 |
Incorrect |
20 ms |
4440 KB |
Output isn't correct |
25 |
Correct |
32 ms |
6604 KB |
Output is correct |
26 |
Incorrect |
20 ms |
4184 KB |
Output isn't correct |
27 |
Incorrect |
32 ms |
4440 KB |
Output isn't correct |
28 |
Incorrect |
19 ms |
4196 KB |
Output isn't correct |
29 |
Incorrect |
27 ms |
4400 KB |
Output isn't correct |
30 |
Incorrect |
17 ms |
4440 KB |
Output isn't correct |
31 |
Incorrect |
0 ms |
2392 KB |
Output isn't correct |
32 |
Incorrect |
0 ms |
2392 KB |
Output isn't correct |