# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
519634 |
2022-01-26T20:44:22 Z |
aryan12 |
Gap (APIO16_gap) |
C++17 |
|
59 ms |
3172 KB |
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
long long Solve1(long long N) {
long long A[N];
long long L = 0, R = N - 1;
long long valL = 0, valR = 1e18;
while(L <= R) {
MinMax(valL, valR, &valL, &valR);
A[L++] = valL;
A[R--] = valR;
valL++;
valR--;
}
long long ans = 0;
for(long long i = 1; i < N; i++) {
ans = max(ans, A[i] - A[i - 1]);
}
return ans;
}
long long Solve2(long long N) {
vector<long long> A;
long long l, r;
long long mn, mx;
MinMax(0, 1e18, &mn, &mx);
A.push_back(mn);
A.push_back(mx);
long long store_mx = mx - 1;
long long len = (mx - mn + N - 2) / (N - 1);
//cout << "\nlen = " << len << "\n";
l = mn, r = mx;
while(l < r) {
l = mn + 1;
r = min(mn + len, store_mx);
MinMax(l, r, &mn, &mx);
//cout << "l = " << l << ", r = " << r << ", mn = " << mn << ", mx = " << mx << "\n";
if(mn == -1) {
mn = r;
if(r == store_mx) break;
continue;
}
A.push_back(mn);
A.push_back(mx);
mn = r;
if(r == store_mx) {
break;
}
}
sort(A.begin(), A.end());
long long ans = 0;
for(int i = 1; i < A.size(); i++) {
ans = max(ans, A[i] - A[i - 1]);
}
return ans;
}
long long findGap(int T, int N)
{
if(T == 1) return Solve1(N);
return Solve2(N);
}
Compilation message
gap.cpp: In function 'long long int Solve2(long long int)':
gap.cpp:53:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int i = 1; i < A.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
0 ms |
200 KB |
Output is correct |
6 |
Correct |
0 ms |
200 KB |
Output is correct |
7 |
Correct |
0 ms |
200 KB |
Output is correct |
8 |
Correct |
0 ms |
200 KB |
Output is correct |
9 |
Correct |
0 ms |
200 KB |
Output is correct |
10 |
Correct |
0 ms |
200 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
9 ms |
584 KB |
Output is correct |
17 |
Correct |
11 ms |
696 KB |
Output is correct |
18 |
Correct |
9 ms |
700 KB |
Output is correct |
19 |
Correct |
9 ms |
688 KB |
Output is correct |
20 |
Correct |
7 ms |
584 KB |
Output is correct |
21 |
Correct |
40 ms |
1848 KB |
Output is correct |
22 |
Correct |
37 ms |
1840 KB |
Output is correct |
23 |
Correct |
43 ms |
1732 KB |
Output is correct |
24 |
Correct |
37 ms |
1856 KB |
Output is correct |
25 |
Correct |
32 ms |
1828 KB |
Output is correct |
26 |
Correct |
43 ms |
1820 KB |
Output is correct |
27 |
Correct |
38 ms |
1728 KB |
Output is correct |
28 |
Correct |
37 ms |
1780 KB |
Output is correct |
29 |
Correct |
37 ms |
1844 KB |
Output is correct |
30 |
Correct |
29 ms |
1864 KB |
Output is correct |
31 |
Correct |
0 ms |
200 KB |
Output is correct |
32 |
Correct |
1 ms |
200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
0 ms |
200 KB |
Output is correct |
5 |
Correct |
0 ms |
200 KB |
Output is correct |
6 |
Correct |
0 ms |
200 KB |
Output is correct |
7 |
Correct |
0 ms |
200 KB |
Output is correct |
8 |
Correct |
0 ms |
200 KB |
Output is correct |
9 |
Correct |
0 ms |
200 KB |
Output is correct |
10 |
Correct |
0 ms |
200 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
13 ms |
888 KB |
Output is correct |
17 |
Correct |
13 ms |
840 KB |
Output is correct |
18 |
Correct |
13 ms |
840 KB |
Output is correct |
19 |
Correct |
13 ms |
804 KB |
Output is correct |
20 |
Correct |
6 ms |
456 KB |
Output is correct |
21 |
Correct |
53 ms |
2172 KB |
Output is correct |
22 |
Correct |
52 ms |
2196 KB |
Output is correct |
23 |
Correct |
58 ms |
2200 KB |
Output is correct |
24 |
Correct |
53 ms |
2196 KB |
Output is correct |
25 |
Correct |
51 ms |
3172 KB |
Output is correct |
26 |
Correct |
54 ms |
2148 KB |
Output is correct |
27 |
Correct |
53 ms |
2220 KB |
Output is correct |
28 |
Correct |
59 ms |
2232 KB |
Output is correct |
29 |
Correct |
53 ms |
2232 KB |
Output is correct |
30 |
Correct |
28 ms |
1352 KB |
Output is correct |
31 |
Correct |
1 ms |
200 KB |
Output is correct |
32 |
Correct |
1 ms |
200 KB |
Output is correct |