#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
// #pragma GCC optimize("Ofast,unroll-loops,fast-math")
// #pragma GCC target("popcnt,sse3,avx")
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
#define sz size()
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define pb push_back
const int mod = ll(1e9)+7; //(b + (a%b)) % b (to mod -1%(10^9+7) correctly in c++ its -1 but its suppose to be 10^9+6
const ll MOD = 998244353; // (a%mod)*(binpow(b,mod-2,mod) = (a/b)%mod
const int M = ll(2e5) + 100;
const long long inf = 2e18;
//const long double eps = 1e-15L;
ll lcm(ll a, ll b) { return (a / __gcd(a,b))*b; }
ll binpow(ll a, ll b, ll m) { ll res=1; a %= m; while(b>0){ if(b&1)res=(res * a) % m; a=(a * a) % m; b/=2; } return res%m;}
void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
void MinMax(long long, long long, long long *, long long *);
long long n, a[M + 10];
long long solve1() {
long long l = 1, r = n, low = 0, high = 1e18;
while(l <= r) {
MinMax(low, high, &a[l], &a[r]);
low = a[l ++] + 1;
high = a[r --] -1;
}
long long ans = 0;
for(int i = 1; i < n; i ++) ans = max(ans, a[i + 1] - a[i]);
return ans;
}
long long solve2() {
MinMax(0ll, 1LL * 1e18, &a[1], &a[n]);
long long block = (a[n] - a[1] + n - 2) / (n - 1), ans = 0, prev = a[1], last = 0;
for(long long l = a[1]; l + block < a[n]; l += block + 1) {
long long x = 0, y = 0;
MinMax(l, l + block , &x, &y);
if(x != -1) {
ans = max(ans, x - prev);
prev = y;
}
last = l;
}
last += block + 1;
long long x = 0, y = 0;
MinMax(last, a[n], &x, &y);
if(x != -1) ans = max(ans, x - prev);
return ans;
}
long long findGap(int T, int N) {
n = N;
if(T == 1) return solve1();
return solve2();
}
Compilation message
gap.cpp: In function 'void Freopen(std::string)':
gap.cpp:34:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gap.cpp:34:76: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 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 |
1 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 |
7 ms |
2544 KB |
Output is correct |
17 |
Correct |
7 ms |
2688 KB |
Output is correct |
18 |
Correct |
8 ms |
2692 KB |
Output is correct |
19 |
Correct |
7 ms |
2692 KB |
Output is correct |
20 |
Correct |
6 ms |
2536 KB |
Output is correct |
21 |
Correct |
28 ms |
3444 KB |
Output is correct |
22 |
Correct |
28 ms |
3448 KB |
Output is correct |
23 |
Correct |
28 ms |
3348 KB |
Output is correct |
24 |
Correct |
28 ms |
3444 KB |
Output is correct |
25 |
Correct |
24 ms |
3700 KB |
Output is correct |
26 |
Correct |
27 ms |
3312 KB |
Output is correct |
27 |
Correct |
27 ms |
3428 KB |
Output is correct |
28 |
Correct |
28 ms |
3452 KB |
Output is correct |
29 |
Correct |
27 ms |
3448 KB |
Output is correct |
30 |
Correct |
22 ms |
3448 KB |
Output is correct |
31 |
Correct |
1 ms |
2592 KB |
Output is correct |
32 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
0 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2644 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 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 |
2640 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
9 ms |
2544 KB |
Output is correct |
17 |
Correct |
10 ms |
2540 KB |
Output is correct |
18 |
Correct |
9 ms |
2540 KB |
Output is correct |
19 |
Correct |
9 ms |
2544 KB |
Output is correct |
20 |
Correct |
5 ms |
2528 KB |
Output is correct |
21 |
Correct |
38 ms |
2680 KB |
Output is correct |
22 |
Correct |
38 ms |
2692 KB |
Output is correct |
23 |
Correct |
38 ms |
2684 KB |
Output is correct |
24 |
Correct |
38 ms |
2588 KB |
Output is correct |
25 |
Correct |
36 ms |
2696 KB |
Output is correct |
26 |
Correct |
38 ms |
2684 KB |
Output is correct |
27 |
Correct |
38 ms |
2684 KB |
Output is correct |
28 |
Correct |
38 ms |
2676 KB |
Output is correct |
29 |
Correct |
38 ms |
2688 KB |
Output is correct |
30 |
Correct |
20 ms |
2680 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
0 ms |
2392 KB |
Output is correct |