#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5;
int T, N;
ll A[MAXN+10], ans;
ll findGap(int _T, int _N)
{
int i, j;
T=_T; N=_N;
if(T==1)
{
ll s=0, t=1e18;
for(i=1, j=N; i<=j; i++, j--)
{
ll a, b;
MinMax(s, t, &a, &b);
A[i]=a; A[j]=b;
s=a+1; t=b-1;
}
for(i=2; i<=N; i++) ans=max(ans, A[i]-A[i-1]);
return ans;
}
else
{
ll s, e;
MinMax(0, 1e18, &s, &e);
if(N==2) return e-s;
ll g=(e-s+N-2)/(ll)(N-1);
ll a, b, p=s, q=s+g;
vector<pll> V;
while(1)
{
if(p>e) break;
if(p>q) break;
MinMax(p, q, &a, &b);
if(a!=-1) V.push_back({a, b});
p=q+1; q=p+g;
q=min(q, e);
}
//for(i=0; i<V.size(); i++) printf("%lld %lld\n", V[i].first, V[i].second);
for(i=1; i<V.size(); i++) ans=max(ans, V[i].first-V[i-1].second);
return ans;
}
}
Compilation message
gap.cpp: In function 'll findGap(int, int)':
gap.cpp:50:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=1; i<V.size(); i++) ans=max(ans, V[i].first-V[i-1].second);
~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
15 ms |
732 KB |
Output is correct |
17 |
Correct |
15 ms |
760 KB |
Output is correct |
18 |
Correct |
15 ms |
760 KB |
Output is correct |
19 |
Correct |
15 ms |
760 KB |
Output is correct |
20 |
Correct |
11 ms |
760 KB |
Output is correct |
21 |
Correct |
55 ms |
1912 KB |
Output is correct |
22 |
Correct |
55 ms |
1888 KB |
Output is correct |
23 |
Correct |
55 ms |
1904 KB |
Output is correct |
24 |
Correct |
55 ms |
1936 KB |
Output is correct |
25 |
Correct |
47 ms |
1912 KB |
Output is correct |
26 |
Correct |
58 ms |
1884 KB |
Output is correct |
27 |
Correct |
55 ms |
1912 KB |
Output is correct |
28 |
Correct |
55 ms |
2040 KB |
Output is correct |
29 |
Correct |
55 ms |
1912 KB |
Output is correct |
30 |
Correct |
41 ms |
1872 KB |
Output is correct |
31 |
Correct |
2 ms |
380 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
20 ms |
972 KB |
Output is correct |
17 |
Correct |
19 ms |
888 KB |
Output is correct |
18 |
Correct |
19 ms |
888 KB |
Output is correct |
19 |
Correct |
20 ms |
888 KB |
Output is correct |
20 |
Correct |
10 ms |
504 KB |
Output is correct |
21 |
Correct |
76 ms |
2288 KB |
Output is correct |
22 |
Correct |
74 ms |
2288 KB |
Output is correct |
23 |
Correct |
74 ms |
2416 KB |
Output is correct |
24 |
Correct |
74 ms |
2288 KB |
Output is correct |
25 |
Correct |
70 ms |
3308 KB |
Output is correct |
26 |
Correct |
75 ms |
2288 KB |
Output is correct |
27 |
Correct |
75 ms |
2288 KB |
Output is correct |
28 |
Correct |
74 ms |
2240 KB |
Output is correct |
29 |
Correct |
76 ms |
2288 KB |
Output is correct |
30 |
Correct |
36 ms |
1528 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |