#include<bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
#include "gap.h"
using namespace std;
#define int long long
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#undef int
long long findGap(int T, int N)
{
#define int long long
if(T == 1){
vector<int> all;
int curl = 1;
int curr = 1e18;
int dd = 0;
while(curl <= curr and dd < N){
int whAt1 = 0;
int whAt2 = 0;
MinMax(curl,curr,&whAt1,&whAt2);
all.pb(whAt1);
if(whAt1 != whAt2)all.pb(whAt2);
dd += 1+(whAt1 != whAt2);
curl = whAt1+1;
curr = whAt2-1;
}
sort(all(all));
int ans = 0;
REP(i,N-1){
ans = max(ans,all[i+1]-all[i]);
}
return ans;
}
else{
int st,en;
int n= N;
MinMax((int)1,(int)1e18,&st,&en);
if(n == 2)return en-st;
int rangesize = (en-st-1+n-2)/(n-1);
int frm = st+1;
vector<int> all;
all.pb(st);
all.pb(en);
REP(i,n){
int oo1,oo2;
if(frm >= en)break;
MinMax(frm,min(frm+rangesize-1,en-1),&oo1,&oo2);
if(oo1 > 0){
all.pb(oo2);
all.pb(oo1);
}
frm += rangesize;
}
int ans = 0;
sort(all(all));
REP(i,(int)all.size()-1){
ans = max(ans,all[i+1]-all[i]);
}
return ans;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
14 ms |
888 KB |
Output is correct |
17 |
Correct |
13 ms |
896 KB |
Output is correct |
18 |
Correct |
14 ms |
896 KB |
Output is correct |
19 |
Correct |
13 ms |
976 KB |
Output is correct |
20 |
Correct |
10 ms |
1004 KB |
Output is correct |
21 |
Correct |
60 ms |
2288 KB |
Output is correct |
22 |
Correct |
54 ms |
2236 KB |
Output is correct |
23 |
Correct |
55 ms |
2288 KB |
Output is correct |
24 |
Correct |
63 ms |
2288 KB |
Output is correct |
25 |
Correct |
48 ms |
2324 KB |
Output is correct |
26 |
Correct |
54 ms |
2288 KB |
Output is correct |
27 |
Correct |
66 ms |
2288 KB |
Output is correct |
28 |
Correct |
57 ms |
2288 KB |
Output is correct |
29 |
Correct |
55 ms |
2288 KB |
Output is correct |
30 |
Correct |
41 ms |
2288 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
18 ms |
896 KB |
Output is correct |
17 |
Correct |
17 ms |
972 KB |
Output is correct |
18 |
Correct |
16 ms |
896 KB |
Output is correct |
19 |
Correct |
17 ms |
896 KB |
Output is correct |
20 |
Correct |
8 ms |
512 KB |
Output is correct |
21 |
Correct |
70 ms |
2288 KB |
Output is correct |
22 |
Correct |
71 ms |
2288 KB |
Output is correct |
23 |
Correct |
78 ms |
2288 KB |
Output is correct |
24 |
Correct |
69 ms |
2288 KB |
Output is correct |
25 |
Correct |
64 ms |
3308 KB |
Output is correct |
26 |
Correct |
70 ms |
2396 KB |
Output is correct |
27 |
Correct |
81 ms |
2288 KB |
Output is correct |
28 |
Correct |
69 ms |
2288 KB |
Output is correct |
29 |
Correct |
69 ms |
2288 KB |
Output is correct |
30 |
Correct |
35 ms |
1528 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
0 ms |
384 KB |
Output is correct |