# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
631637 |
2022-08-18T10:54:24 Z |
minhcool |
Gap (APIO16_gap) |
C++17 |
|
74 ms |
6980 KB |
#include<bits/stdc++.h>
using namespace std;
#include "gap.h"
//#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
//const int N = ;
const int oo = 1e18 + 7, mod = 1e9 + 7;
const int N = 5e5 + 5;
long long int findGap(int T, int N){
if(T == 1){
long long lstx = 0, lsty = 1e18, a, b;
set<long long> se;
for(int i = 1; i <= (N + 1) / 2; i++){
MinMax(lstx, lsty, &a, &b);
if(a != -1) se.insert(a);
if(b != -1) se.insert(b);
lstx = a + 1, lsty = b - 1;
}
vector<long long> arr;
for(auto it : se) arr.pb(it);
long long answer = 0;
for(int i = 1; i < arr.size(); i++){
answer = max(answer, arr[i] - arr[i - 1]);
}
return answer;
}
else{
long long mini, maxi;
MinMax(0, 1e18, &mini, &maxi);
long long gap = (maxi - mini - 1) / (N - 1) + 1;// exist a gap where no numbers in there => ans >= gap => same gap don't care
long long le = mini + 1, answer = 0, lst = mini;
while(le + gap <= maxi){
long long temp1, temp2;
MinMax(le, le + gap - 1, &temp1, &temp2);
le += gap;
if(temp1 == -1) continue;
answer = max(answer, temp1 - lst);
lst = temp2;
}
if(le < maxi){
long long temp1, temp2;
MinMax(le, maxi - 1, &temp1, &temp2);
if(temp1 != -1){
answer = max(answer, temp1 - lst);
lst = temp2;
}
}
answer = max(answer, maxi - lst);
return answer;
}
}
Compilation message
gap.cpp:19:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
19 | const int oo = 1e18 + 7, mod = 1e9 + 7;
| ~~~~~^~~
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:37:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i = 1; i < arr.size(); i++){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
14 ms |
2036 KB |
Output is correct |
17 |
Correct |
13 ms |
1964 KB |
Output is correct |
18 |
Correct |
17 ms |
2036 KB |
Output is correct |
19 |
Correct |
13 ms |
2040 KB |
Output is correct |
20 |
Correct |
11 ms |
2000 KB |
Output is correct |
21 |
Correct |
60 ms |
6832 KB |
Output is correct |
22 |
Correct |
59 ms |
6944 KB |
Output is correct |
23 |
Correct |
60 ms |
6980 KB |
Output is correct |
24 |
Correct |
57 ms |
6888 KB |
Output is correct |
25 |
Correct |
57 ms |
6852 KB |
Output is correct |
26 |
Correct |
62 ms |
6932 KB |
Output is correct |
27 |
Correct |
58 ms |
6892 KB |
Output is correct |
28 |
Correct |
58 ms |
6852 KB |
Output is correct |
29 |
Correct |
74 ms |
6936 KB |
Output is correct |
30 |
Correct |
54 ms |
6864 KB |
Output is correct |
31 |
Correct |
0 ms |
208 KB |
Output is correct |
32 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
12 ms |
516 KB |
Output is correct |
17 |
Correct |
12 ms |
464 KB |
Output is correct |
18 |
Correct |
13 ms |
464 KB |
Output is correct |
19 |
Correct |
12 ms |
464 KB |
Output is correct |
20 |
Correct |
6 ms |
520 KB |
Output is correct |
21 |
Correct |
52 ms |
1044 KB |
Output is correct |
22 |
Correct |
50 ms |
1056 KB |
Output is correct |
23 |
Correct |
57 ms |
1084 KB |
Output is correct |
24 |
Correct |
58 ms |
1056 KB |
Output is correct |
25 |
Correct |
45 ms |
1088 KB |
Output is correct |
26 |
Correct |
53 ms |
968 KB |
Output is correct |
27 |
Correct |
60 ms |
1048 KB |
Output is correct |
28 |
Correct |
53 ms |
1084 KB |
Output is correct |
29 |
Correct |
59 ms |
976 KB |
Output is correct |
30 |
Correct |
27 ms |
988 KB |
Output is correct |
31 |
Correct |
0 ms |
208 KB |
Output is correct |
32 |
Correct |
0 ms |
208 KB |
Output is correct |